I created a simple App below with
MainActivity -> ContainerFragment -> MainFragment
The ContainerFragment uses replace
to commit the MainFragment.
I turn ON doesn't keep Activity`
When MainFragment call startActivityForResult
, and return from the activity, the onActivityResult
is not called.
This doesn't happen when
- It is a single Fragment. (not nested)
Don't Keep Activity
is OFF- When ContainerFragment uses
add
to commit the MainFragment.
To replicate the problem, download the code in the following github and run it. (Remember to turn on Don't Keep Activity
). Click Start Activity..
, and then click End Activity
and expect a Toast (no Toast, shows that the onActivityResult
in the fragment is not called)
https://github.com/elye/issue_android_onactivityresult_not_called
Apparently there was previously a reported nested Fragment can't get onActivityResult
in the past as posted in https://stackoverflow.com/a/36239436/3286489, but stated has been resolved in Android Support Library 23.2.1. But for my case, I tried on Android Support Library 28 (Android Pie). So this is still a valid issue I believe.
Share it here in case I am wrong, and there's some explanation to this out there.
In case workaround, there's one recommended in https://inthecheesefactory.com/blog/how-to-fix-nested-fragment-onactivityresult-issue/en.
Another workaround as reported in https://stackoverflow.com/a/20543245/3286489