I have an adapter class :
public class AdapterAllAddress extends BaseExpandableListAdapter {
private Context context;
public AdapterAllAddress(Context context,
ArrayList<AllAddressesGroup> groups) {
// TODO Auto-generated constructor stub
this.context = context;
}
}
I want to call startActivityForResult
when a button click , I know I can call startActivity
like this:
context.startActivity()
but i am looking for activity with results, how please ?
How do I call onActivityResult in Recyclerview adapter? create a public method in ImageAdapter class and pass data using myImageAdapter object. – Jaydeep Devda. write onActivityResult override method in showImages Activity and inside result ok pass data to adapter using myImageAdapter.
But recently startActivityForResult() method is deprecated in AndroidX. Android came up with ActivityResultCallback (also called Activity Results API) as an alternative for it. Step 1: You just have to create an ActivityResultLauncher and pass following parameters handle onActivityResult in it as shown above.
The android startActivityForResult method, requires a result from the second activity (activity to be invoked). In such case, we need to override the onActivityResult method that is invoked automatically when second activity returns result.
It has deprecated startActivityForResult in favour of registerForActivityResult . It was one of the first fundamentals that any Android developer has learned, and the backbone of Android's way of communicating between two components.
yourButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(context, YourNewActivity.class);
((Activity) context).startActivityForResult(intent, resultCode);
}
});
I just wanted to point a detail which i faced in my case E/ActivityThread(31584): Performing stop of activity that is not resumed: {com.example.test/activities.MainActivity} most probably you are passing getApplicationContext() to the adapter's constructor . In order to avoid this you must provide "CallingActivity.this" to the adapter's constructor as the context object , keep this in mind .
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