Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What is happening is that the activity containing the fragments has been disposed of. This can happen at any time while the activity is not being displayed - what your user did was change a developer setting which aggressively destroys activities to allow you to see coding issues like this one. The problem can still happen, and the fewer resources a device has available (either because it has little memory, or because a lot of other things are running), the more often Android will do this.</p> <p>Having explained the background to the underlying issue, lets move on to the specific problem in your <code>onActivityResult()</code> code. This method is invoked at a point in the view lifecycle before the context around your fragments and activity has been reconstituted, so you can't do any meaningful work with your fragments in this method and be sure it will always work. Instead save the response in a class level variable and use it in <code>onResume()</code> which will be called whether the activity was destroyed or not.</p> <p>As an aside, you should move the <code>onActivityResult()</code> method into the fragment - and always invoke <code>super.onActivityResult()</code> before your own code.</p> <p>Finally note that Android destroys and recreates fragments at its own whim (for example, when you rotate your device, all your fragments are destroyed and re-created). Therefore you should ensure you understand and work with the Activity and Fragment lifecycles, and not against them as Alex's solution suggests. This will only lead to other difficult to diagnose problems.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload