is it possible to have method onActivityResume
within adapter
& call startActivityForResult
?
But recently startActivityForResult() method is deprecated in AndroidX. Android came up with ActivityResultCallback (also called Activity Results API) as an alternative for it.
The request code is any int value. The request code identifies the return result when the result arrives. ( You can call startActivityForResult more than once before you get any results. When results arrive, you use the request code to distinguish one result from another.
onActivityResult , startActivityForResult , requestPermissions , and onRequestPermissionsResult are deprecated on androidx.
Yes. Just pass the context of the activity to the adapter in the adapter's constructor (here stored as mContext). In getView, just call
((Activity) mContext).startActivityForResult(intent,REQUEST_FOR_ACTIVITY_CODE);
Not necessarily pass to pass context in adapter's constructor. You can get context from parent ViewGroup. Sample for RecyclerView adapter:
Context mContext; @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { mContext = parent.getContext(); ... }
Sample for ListView BaseAdapter
Context mContext; @Override public View getView(int position, View convertView, ViewGroup parent) { mContext = parent.getContext(); ... }
And use it wherever you want
((Activity) mContext).startActivityForResult(intent, REQUEST_FOR_ACTIVITY_CODE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With