diff --git a/api/current.txt b/api/current.txt index 80ce562268e55..993f9fbd15d31 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4430,6 +4430,7 @@ package android.app { method public void onActivityResult(int, int, android.content.Intent); method public void onAttach(android.content.Context); method public deprecated void onAttach(android.app.Activity); + method public void onAttachFragment(android.app.Fragment); method public void onConfigurationChanged(android.content.res.Configuration); method public boolean onContextItemSelected(android.view.MenuItem); method public void onCreate(android.os.Bundle); diff --git a/api/system-current.txt b/api/system-current.txt index 3a3de7c29d5ec..461dcea968c7d 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -4575,6 +4575,7 @@ package android.app { method public void onActivityResult(int, int, android.content.Intent); method public void onAttach(android.content.Context); method public deprecated void onAttach(android.app.Activity); + method public void onAttachFragment(android.app.Fragment); method public void onConfigurationChanged(android.content.res.Configuration); method public boolean onContextItemSelected(android.view.MenuItem); method public void onCreate(android.os.Bundle); diff --git a/api/test-current.txt b/api/test-current.txt index da4aef906619b..da5136d2e553d 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -4431,6 +4431,7 @@ package android.app { method public void onActivityResult(int, int, android.content.Intent); method public void onAttach(android.content.Context); method public deprecated void onAttach(android.app.Activity); + method public void onAttachFragment(android.app.Fragment); method public void onConfigurationChanged(android.content.res.Configuration); method public boolean onContextItemSelected(android.view.MenuItem); method public void onCreate(android.os.Bundle); diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java index 7ef6d414ed84d..a637ef4f9c549 100644 --- a/core/java/android/app/Fragment.java +++ b/core/java/android/app/Fragment.java @@ -1429,6 +1429,18 @@ public class Fragment implements ComponentCallbacks2, OnCreateContextMenuListene mCalled = true; } + /** + * Called when a fragment is attached as a child of this fragment. + * + *

This is called after the attached fragment's onAttach and before + * the attached fragment's onCreate if the fragment has not yet had a previous + * call to onCreate.

+ * + * @param childFragment child fragment being attached + */ + public void onAttachFragment(Fragment childFragment) { + } + /** * Called when a fragment is first attached to its context. * {@link #onCreate(Bundle)} will be called after this. diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index 13b271681cf86..cd7665cf1163e 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -941,6 +941,8 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate } if (f.mParentFragment == null) { mHost.onAttachFragment(f); + } else { + f.mParentFragment.onAttachFragment(f); } if (!f.mRetaining) {