OSDN Git Service

Less lazy child FragmentManager creation
authorAdam Powell <adamp@google.com>
Wed, 11 May 2016 20:45:33 +0000 (13:45 -0700)
committerAdam Powell <adamp@google.com>
Wed, 11 May 2016 20:45:33 +0000 (13:45 -0700)
Framework edition

Fix a bug where child FragmentManagers moving too lazily into the
CREATED state and beyond caused child fragments to not be
attached/created when expected.

Bug 25019275

Change-Id: I04ff0d3bcb693178a6ee3057da591392defdbcf8

core/java/android/app/Fragment.java
core/java/android/app/FragmentManager.java

index f4fe1eb..7ef6d41 100644 (file)
@@ -1486,6 +1486,10 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
         final int version = context != null ? context.getApplicationInfo().targetSdkVersion : 0;
         if (version >= Build.VERSION_CODES.N) {
             restoreChildFragmentState(savedInstanceState, true);
+            if (mChildFragmentManager != null
+                    && !mChildFragmentManager.isStateAtLeast(Fragment.CREATED)) {
+                mChildFragmentManager.dispatchCreate();
+            }
         }
     }
 
index d795385..13b2716 100644 (file)
@@ -870,6 +870,10 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
         }
     }
 
+    boolean isStateAtLeast(int state) {
+        return mCurState >= state;
+    }
+
     void moveToState(Fragment f, int newState, int transit, int transitionStyle,
             boolean keepActive) {
         if (DEBUG && false) Log.v(TAG, "moveToState: " + f