Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b963c99c authored by Adam Powell's avatar Adam Powell
Browse files

Don't performPendingDeferredStart on fragments that aren't added

Framework edition

When setting a user visibility hint on a fragment it was possible to
have a FragmentManager already set due to a transaction being composed
but before the commit, so only checking that we have one isn't
sufficient for determining whether we should perform a pending
deferred start. This could happen easily with ViewPager adapters. Use
isAdded() instead.

Also fix a bug where we could set our internal tracking of fragments
that need a deferred start incorrectly.

Bug 27814550

Change-Id: I3be65728650c48d27a3a9dd4ca15f52006d14ab9
parent 6c4af8c9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1033,11 +1033,11 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
     *                        false if it is not.
     */
    public void setUserVisibleHint(boolean isVisibleToUser) {
        if (!mUserVisibleHint && isVisibleToUser && mState < STARTED && mFragmentManager != null) {
        if (!mUserVisibleHint && isVisibleToUser && mState < STARTED && isAdded()) {
            mFragmentManager.performPendingDeferredStart(this);
        }
        mUserVisibleHint = isVisibleToUser;
        mDeferStart = !isVisibleToUser;
        mDeferStart = mState < STARTED && !isVisibleToUser;
    }

    /**