Sdk 25.1.0 Crash On Commitnow When Call Within Onbackstackchanged(). Google Bug?
I have an activity, with 2 fragments FragmentMainOne and FragmentMainTwo that will swap whenever onBackStackChanged() is called public class MainActivity extends AppCompatActivity
Solution 1:
After investigation, looks like this is a new constraint introduced in Support Library 25.1.0.
The crash happens on
privatevoidensureExecReady(boolean allowStateLoss) {
if (mExecutingActions) {
thrownewIllegalStateException("FragmentManager is already executing transactions");
}
// ... more codes
}
So something has set the mExecutingActions
to true.
Found out that in 25.1.0 FragmentManager class, the codes below is new
privatebooleanpopBackStackImmediate(String name, int id, int flags) {
execPendingActions();
ensureExecReady(true);
booleanexecutePop= popBackStackState(mTmpRecords, mTmpIsPop, name, id, flags);
if (executePop) {
mExecutingActions = true;
try {
optimizeAndExecuteOps(mTmpRecords, mTmpIsPop);
} finally {
cleanupExec(); // setting mExecutingAction = false
}
}
doPendingDeferredStart();
return executePop;
}
Where it set the mExecutingActions
to true when popping the fragment stack. This is not set before 25.1.0. I view this as explicit introduce prevention to ensure backstack popping is complete before on commit another fragment.
To workaround the issue, just us commit()
instead if commitNow()
.
For more illustration of the issue, refers to https://medium.com/@elye.project/new-in-support-library-25-1-0-android-disallow-commitnow-on-onbackstackchanged-227c651eefb2#.p9ds8m8ws
Post a Comment for "Sdk 25.1.0 Crash On Commitnow When Call Within Onbackstackchanged(). Google Bug?"