Skip to content

Commit

Permalink
Fix no view found crash in fragment manager.
Browse files Browse the repository at this point in the history
This change fixes issue reported in #54. The issue was caused by the fragment transaction that run past the moment when container view is detached. This could happen when container is quickly added and removed as fragment transactions sometimes may take long time to execute. Unfortunately enqueued fragment transactions cannot be cancelled, so to make sure that transaction isn't run past container unmount we call executePendingTransactions right before the screen is detached.
  • Loading branch information
kmagiera committed Feb 24, 2020
1 parent b29e634 commit 2ff9fed
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ protected void onAttachedToWindow() {

@Override
protected void onDetachedFromWindow() {
// if there are pending transactions and this view is about to get detached we need to perform
// them here as otherwise fragment manager will crash because it won't be able to find container
// view.
mFragmentManager.executePendingTransactions();
super.onDetachedFromWindow();
mIsAttached = false;
}
Expand Down

0 comments on commit 2ff9fed

Please sign in to comment.