I have fragment (x) inside FragmentStatePagerAdapter that is inside activity (y) , in fragment (x) i have startActivity to another actvity (z) , how to send listener or callback from activity (z) into activity (y)
Asked
Active
Viewed 1,092 times
0
-
you can try for https://stackoverflow.com/questions/28392946/adding-parcelable-to-an-interface-class-for-custom-objects – Pankaj Deshpande Oct 04 '18 at 08:27
2 Answers
1
You can't. But you can use startActivityForResult to start activity(z). Before activity(z) activity is finishing, you have to set a result. Then you can handle this result in activity(y).
Have a look on this https://developer.android.com/training/basics/intents/result

Maik Peschutter
- 603
- 4
- 9
0
Start your second activity for result
static final int PICK_CONTACT_REQUEST = 1; // The request code
...
private void pickContact() {
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
}
Then before finish second activity setup result intent
Intent resultIntent = new Intent()
resultIntent.putExtra("SOME_TAG", SOME RESULT HERE)
activity.setResult(Activity.RESULT_OK, resultIntent);
activity.finish();
Then in first activity this intent will be handled in onActivityResult method
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
// The user picked a contact.
// The Intent's data Uri identifies which contact was selected.
// Do something with the contact here (bigger example below)
}
}
}

Konstantin Volkov
- 300
- 1
- 9