Note that there are some explanatory texts on larger screens.

plurals
  1. POFragment already added IllegalStateException
    primarykey
    data
    text
    <p>I use this method on my container Activity to show a BFrag</p> <pre><code>public void showBFrag() { // Start a new FragmentTransaction FragmentTransaction fragmentTransaction = mFragmentMgr.beginTransaction(); if(mBFrag.isAdded()) { Log.d(LOG_TAG, "Show() BFrag"); fragmentTransaction.show(mBFrag); } else { Log.d(LOG_TAG, "Replacing AFrag -&gt; BFrag"); fragmentTransaction.replace(R.id.operation_fragments_frame, mBFrag); } // Keep the transaction in the back stack so it will be reversed when backbutton is pressed fragmentTransaction.addToBackStack(null); // Commit transaction fragmentTransaction.commit(); } </code></pre> <p>I call it from my container Activity; for the first time: </p> <ul> <li>gets into the else statement and mBFrag replace mAFrag. </li> </ul> <p>Then I press the back button:</p> <ul> <li>and the operation is reversed (mAFrag is shown but.. does mBFrag is removed?). </li> </ul> <p>Then I go forward again by calling showBFrag() from the same Activity: </p> <ul> <li>and it gets AGAIN into the else statement. (so I can deduce that mBFrag is NOT ADDED)</li> <li>but I got a <strong>Fragment already added IllegalStateException</strong>... (so why it didn't get into the if statement instead?)</li> </ul> <p>So:</p> <ol> <li>Why is the isAdded() method not returning TRUE if I'm getting a <strong>Fragment already added IllegalStateException</strong>?? </li> <li>Does popBackStack operation completely remove previously added fragments?</li> <li>What behaviour am I misunderstanding? </li> </ol> <p>EDIT: Here is the complete info of the exception.</p> <pre><code>06-07 12:08:32.730: ERROR/AndroidRuntime(8576): java.lang.IllegalStateException: Fragment already added: BFrag{40b28158 id=0x7f0c0085} 06-07 12:08:32.730: ERROR/AndroidRuntime(8576): at android.app.BackStackRecord.doAddOp(BackStackRecord.java:322) 06-07 12:08:32.730: ERROR/AndroidRuntime(8576): at android.app.BackStackRecord.replace(BackStackRecord.java:360) 06-07 12:08:32.730: ERROR/AndroidRuntime(8576): at android.app.BackStackRecord.replace(BackStackRecord.java:352) 06-07 12:08:32.730: ERROR/AndroidRuntime(8576): at myPackageName.containerActivity.showBFrag() // This line: "fragmentTransaction.replace(R.id.operation_fragments_frame, mBFrag);" </code></pre>
    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.
 

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