Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android FLAG_ACTIVITY_FORWARD_RESULT howto
Nav flow is: A => B => C => A with results from C
If you're using fragments please note that "onActivityResult" will be called according to where "startActivityForResult" is called (method "startActivityForResult" is available in both, activity and fragment)
ActivityA
startActivityForResult(intentB, 22);
ActivityB
intentC.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivity(intentC);
finish();
ActivityC
setResult(99);
finish();
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Dec 16, 2016

I think that finish() in ActivityB is unnecessary.

@danielwilson1702

This comment has been minimized.

Copy link

@danielwilson1702 danielwilson1702 commented Feb 28, 2018

This is actually perfect been looking for this exact description. You need to finish ActivityB otherwise you are left looking at it when ActivityC closes. Something that got me was I was in a fragment in Activity B, so had to call getActivity().startActivity() instead of the fragment's own startActivity()

@nvquangth

This comment has been minimized.

Copy link

@nvquangth nvquangth commented Nov 14, 2018

Awesome!

@YuriPopiv

This comment has been minimized.

Copy link

@YuriPopiv YuriPopiv commented Nov 17, 2020

Amazing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment