summaryrefslogtreecommitdiffstats
path: root/core/java/android/app/Fragment.java
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2014-06-20 12:51:12 -0700
committerAdam Powell <adamp@google.com>2014-06-24 12:29:32 -0700
commit371a809179c843d7ae661a10bc9b4b8cfcaff566 (patch)
tree0b28c3bbb236aadddfd427112908d7ab464176f7 /core/java/android/app/Fragment.java
parent775a159e80ad9c174dab656b4e23032d525e5bd2 (diff)
downloadframeworks_base-371a809179c843d7ae661a10bc9b4b8cfcaff566.zip
frameworks_base-371a809179c843d7ae661a10bc9b4b8cfcaff566.tar.gz
frameworks_base-371a809179c843d7ae661a10bc9b4b8cfcaff566.tar.bz2
Inflate fragments from layout into child FragmentManagers
Previously, if an app inflated a layout in a Fragment's onCreateView that itself had fragments included, those fragments would be added to the Activity-level FragmentManager and would not share the same lifecycle with the fragment it was inflated for. This led to some nasty management headaches. If an app targets L or above, add the fragment to the child FragmentManager of the current fragment when inflated using the LayoutInflater passed to the parent fragment. Bug 12763389 Change-Id: Iad4ed7d5df602aea9579bf1503e206fa894630c1
Diffstat (limited to 'core/java/android/app/Fragment.java')
-rw-r--r--core/java/android/app/Fragment.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index 6c0d379..2ff3d57 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -23,6 +23,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -1104,7 +1105,15 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene
* inflation. Maybe this should become a public API. Note sure.
*/
public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
- return mActivity.getLayoutInflater();
+ // Newer platform versions use the child fragment manager's LayoutInflaterFactory.
+ if (mActivity.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.L) {
+ LayoutInflater result = mActivity.getLayoutInflater().cloneInContext(mActivity);
+ getChildFragmentManager(); // Init if needed; use raw implementation below.
+ result.setPrivateFactory(mChildFragmentManager.getLayoutInflaterFactory());
+ return result;
+ } else {
+ return mActivity.getLayoutInflater();
+ }
}
/**