Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, you should read my <a href="http://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html" rel="noreferrer"><strong>blog post</strong></a> for more information (it talks about why this exception happens and what you can do to prevent it).</p> <p>Calling <code>commitAllowingStateLoss()</code> is more of a hack than a fix. State loss is bad and should be avoided at all costs. At the time that <code>onActivityResult()</code> is called, the activity/fragment's state may not yet have been restored, and therefore any transactions that happen during this time will be lost as a result. This is a very important bug which must be addressed! (Note that the bug only happens when your <code>Activity</code> is coming back after having been killed by the system... which, depending on how much memory the device has, can sometimes be rare... so this sort of bug is not something that is very easy to catch while testing).</p> <p>Try moving your transactions into <code>onPostResume()</code> instead (note that <code>onPostResume()</code> is always called after <code>onResume()</code> and <code>onResume()</code> is always called after <code>onActivityResult()</code>):</p> <pre><code>private boolean mReturningWithResult = false; @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); mReturningWithResult = true; } @Override protected void onPostResume() { super.onPostResume(); if (mReturningWithResult) { // Commit your transactions here. } // Reset the boolean flag back to false for next time. mReturningWithResult = false; } </code></pre> <p>This might seem a little weird, but doing this sort of thing is necessary to ensure that your <code>FragmentTransaction</code>s are always committed <em>after</em> the <code>Activity</code>'s state has been restored to its original state (<code>onPostResume()</code> is guaranteed to be called after the <code>Activity</code>'s state has been restored).</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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