save "retain loader" state DO NOT MERGE
We cannot pull the "retain loader" state from the Activity; an Activity may
not always be hosting a Fragment. Instead, save the "retain loader" state
inside the individual fragments.
Bug: 23838271
Change-Id: I8358183a7689b5a571ea7be03d769186b2812600
(cherry picked from commit c5ac16f531)
This commit is contained in:
committed by
Chris Banes
parent
5695a7f640
commit
d8b47855a3
@@ -460,6 +460,9 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
||||
// If set this fragment is being retained across the current config change.
|
||||
boolean mRetaining;
|
||||
|
||||
// If set this fragment's loaders are being retained across the current config change.
|
||||
boolean mRetainLoader;
|
||||
|
||||
// If set this fragment has menu items to contribute.
|
||||
boolean mHasMenu;
|
||||
|
||||
@@ -2401,7 +2404,7 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
|
||||
mLoaderManager = mHost.getLoaderManager(mWho, mLoadersStarted, false);
|
||||
}
|
||||
if (mLoaderManager != null) {
|
||||
if (mRetaining) {
|
||||
if (mRetainLoader) {
|
||||
mLoaderManager.doRetain();
|
||||
} else {
|
||||
mLoaderManager.doStop();
|
||||
|
||||
@@ -341,6 +341,7 @@ public class FragmentController {
|
||||
*/
|
||||
public void doLoaderStop(boolean retain) {
|
||||
mHost.doLoaderStop(retain);
|
||||
mHost.mFragmentManager.setRetainLoader(retain);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -869,6 +869,17 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
|
||||
}
|
||||
}
|
||||
|
||||
void setRetainLoader(boolean retain) {
|
||||
if (mActive != null) {
|
||||
for (int i=0; i<mActive.size(); i++) {
|
||||
Fragment f = mActive.get(i);
|
||||
if (f != null) {
|
||||
f.mRetainLoader = retain;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void moveToState(Fragment f, int newState, int transit, int transitionStyle,
|
||||
boolean keepActive) {
|
||||
if (DEBUG && false) Log.v(TAG, "moveToState: " + f
|
||||
|
||||
Reference in New Issue
Block a user