Understand the behavior of startActivityForResult for Fragment and Activity

The basic startActivityForResult Activity flow

Several notes here:

Undocumented startActivityForResult Fragment Flow

The fragment flow illustrated.

Let’s more elaborate on it.

A. The behavior of Activity’s startActivityForResult is different from Fragment’s startActivityForResult

B. If we override activity’s onActivityResult, make sure we have super.onActivityResult in place

C. The requestCode seen in activity’s onActivityResult is different from the one fragment provided

D. When an activity is restored from the state (i.e. onStateInstance != null), it should avoid recreate its fragment.

Senior Software Engineer | Android | Java | Kotlin|Xamarin Native Android|Flutter