florent37 / InlineActivityResult

Receive the activity result directly after the startActivityForResult with InlineActivityResult
MIT License
273 stars 28 forks source link

Fix infinite start for result #6

Closed fleficher closed 5 years ago

fleficher commented 5 years ago

Fix issue #5

When the activity/fragment that calls the startForResult gets destroyed and the called Intent finish:

1- The ActivityResultFragment#onActivityResult gets called but the listener is null (because the fragment has been recreated), which results in the fragment not being removed from the fragment manager.

2- The onResume is called and the started intent is called again.

Solution: Avoid calling the startActivityForResult if it has already been called by removing the Fragment when onActivityResult is called even if the listener is null.

Drawbacks: When the calling activity is destroyed after calling startForResult, the Intent result cannot be propagated to it. I couldn't find a proper solution to get it works in this case.