summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2017-04-27 22:18:00 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2017-04-27 22:18:11 +0000
commit13d03e504db4737bf37db5cc4ffc179f8e490bcb (patch)
treed64ed4d94fef5b93805b74bb04d81233e22366ec
parentf9dc09f4ea660b7dbd0d3fc97c2c73235736f37f (diff)
parent10d69ac2503c0515a07b2bb95041af7b5b6af3f9 (diff)
Merge "Address API feedback for new fragment APIs" into oc-dev
-rw-r--r--api/current.txt3
-rw-r--r--api/system-current.txt3
-rw-r--r--api/test-current.txt3
-rw-r--r--core/java/android/app/BackStackRecord.java2
-rw-r--r--core/java/android/app/FragmentManager.java32
-rw-r--r--core/java/android/app/FragmentTransaction.java14
6 files changed, 50 insertions, 7 deletions
diff --git a/api/current.txt b/api/current.txt
index bcf366266a85..9d440e648bcb 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -4818,6 +4818,7 @@ package android.app {
method public void onFragmentDetached(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentPaused(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentPreAttached(android.app.FragmentManager, android.app.Fragment, android.content.Context);
+ method public void onFragmentPreCreated(android.app.FragmentManager, android.app.Fragment, android.os.Bundle);
method public void onFragmentResumed(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentSaveInstanceState(android.app.FragmentManager, android.app.Fragment, android.os.Bundle);
method public void onFragmentStarted(android.app.FragmentManager, android.app.Fragment);
@@ -4850,10 +4851,10 @@ package android.app {
method public abstract android.app.FragmentTransaction hide(android.app.Fragment);
method public abstract boolean isAddToBackStackAllowed();
method public abstract boolean isEmpty();
- method public abstract android.app.FragmentTransaction postOnCommit(java.lang.Runnable);
method public abstract android.app.FragmentTransaction remove(android.app.Fragment);
method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment);
method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment, java.lang.String);
+ method public abstract android.app.FragmentTransaction runOnCommit(java.lang.Runnable);
method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(int);
method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(java.lang.CharSequence);
method public abstract android.app.FragmentTransaction setBreadCrumbTitle(int);
diff --git a/api/system-current.txt b/api/system-current.txt
index c239fbafc92b..0a9a5df0fc31 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -4986,6 +4986,7 @@ package android.app {
method public void onFragmentDetached(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentPaused(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentPreAttached(android.app.FragmentManager, android.app.Fragment, android.content.Context);
+ method public void onFragmentPreCreated(android.app.FragmentManager, android.app.Fragment, android.os.Bundle);
method public void onFragmentResumed(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentSaveInstanceState(android.app.FragmentManager, android.app.Fragment, android.os.Bundle);
method public void onFragmentStarted(android.app.FragmentManager, android.app.Fragment);
@@ -5018,10 +5019,10 @@ package android.app {
method public abstract android.app.FragmentTransaction hide(android.app.Fragment);
method public abstract boolean isAddToBackStackAllowed();
method public abstract boolean isEmpty();
- method public abstract android.app.FragmentTransaction postOnCommit(java.lang.Runnable);
method public abstract android.app.FragmentTransaction remove(android.app.Fragment);
method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment);
method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment, java.lang.String);
+ method public abstract android.app.FragmentTransaction runOnCommit(java.lang.Runnable);
method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(int);
method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(java.lang.CharSequence);
method public abstract android.app.FragmentTransaction setBreadCrumbTitle(int);
diff --git a/api/test-current.txt b/api/test-current.txt
index 7ae80403d0fa..862ce61728ea 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -4831,6 +4831,7 @@ package android.app {
method public void onFragmentDetached(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentPaused(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentPreAttached(android.app.FragmentManager, android.app.Fragment, android.content.Context);
+ method public void onFragmentPreCreated(android.app.FragmentManager, android.app.Fragment, android.os.Bundle);
method public void onFragmentResumed(android.app.FragmentManager, android.app.Fragment);
method public void onFragmentSaveInstanceState(android.app.FragmentManager, android.app.Fragment, android.os.Bundle);
method public void onFragmentStarted(android.app.FragmentManager, android.app.Fragment);
@@ -4863,10 +4864,10 @@ package android.app {
method public abstract android.app.FragmentTransaction hide(android.app.Fragment);
method public abstract boolean isAddToBackStackAllowed();
method public abstract boolean isEmpty();
- method public abstract android.app.FragmentTransaction postOnCommit(java.lang.Runnable);
method public abstract android.app.FragmentTransaction remove(android.app.Fragment);
method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment);
method public abstract android.app.FragmentTransaction replace(int, android.app.Fragment, java.lang.String);
+ method public abstract android.app.FragmentTransaction runOnCommit(java.lang.Runnable);
method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(int);
method public abstract android.app.FragmentTransaction setBreadCrumbShortTitle(java.lang.CharSequence);
method public abstract android.app.FragmentTransaction setBreadCrumbTitle(int);
diff --git a/core/java/android/app/BackStackRecord.java b/core/java/android/app/BackStackRecord.java
index 65c5b4f702b2..46e6defbb41a 100644
--- a/core/java/android/app/BackStackRecord.java
+++ b/core/java/android/app/BackStackRecord.java
@@ -621,7 +621,7 @@ final class BackStackRecord extends FragmentTransaction implements
}
@Override
- public FragmentTransaction postOnCommit(Runnable runnable) {
+ public FragmentTransaction runOnCommit(Runnable runnable) {
if (runnable == null) {
throw new IllegalArgumentException("runnable cannot be null");
}
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index fdd1b7e72352..63c0ef33ff36 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -452,6 +452,18 @@ public abstract class FragmentManager {
public void onFragmentAttached(FragmentManager fm, Fragment f, Context context) {}
/**
+ * Called right before the fragment's {@link Fragment#onCreate(Bundle)} method is called.
+ * This is a good time to inject any required dependencies or perform other configuration
+ * for the fragment.
+ *
+ * @param fm Host FragmentManager
+ * @param f Fragment changing state
+ * @param savedInstanceState Saved instance bundle from a previous instance
+ */
+ public void onFragmentPreCreated(FragmentManager fm, Fragment f,
+ Bundle savedInstanceState) {}
+
+ /**
* Called after the fragment has returned from the FragmentManager's call to
* {@link Fragment#onCreate(Bundle)}. This will only happen once for any given
* fragment instance, though the fragment may be attached and detached multiple times.
@@ -1218,6 +1230,7 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
dispatchOnFragmentAttached(f, mHost.getContext(), false);
if (!f.mRetaining) {
+ dispatchOnFragmentPreCreated(f, f.mSavedFragmentState, false);
f.performCreate(f.mSavedFragmentState);
dispatchOnFragmentCreated(f, f.mSavedFragmentState, false);
} else {
@@ -3274,6 +3287,25 @@ final class FragmentManagerImpl extends FragmentManager implements LayoutInflate
}
}
+ void dispatchOnFragmentPreCreated(Fragment f, Bundle savedInstanceState,
+ boolean onlyRecursive) {
+ if (mParent != null) {
+ FragmentManager parentManager = mParent.getFragmentManager();
+ if (parentManager instanceof FragmentManagerImpl) {
+ ((FragmentManagerImpl) parentManager)
+ .dispatchOnFragmentPreCreated(f, savedInstanceState, true);
+ }
+ }
+ if (mLifecycleCallbacks == null) {
+ return;
+ }
+ for (Pair<FragmentLifecycleCallbacks, Boolean> p : mLifecycleCallbacks) {
+ if (!onlyRecursive || p.second) {
+ p.first.onFragmentPreCreated(this, f, savedInstanceState);
+ }
+ }
+ }
+
void dispatchOnFragmentCreated(Fragment f, Bundle savedInstanceState, boolean onlyRecursive) {
if (mParent != null) {
FragmentManager parentManager = mParent.getFragmentManager();
diff --git a/core/java/android/app/FragmentTransaction.java b/core/java/android/app/FragmentTransaction.java
index a0e5a4ec6f1f..c910e9035a3f 100644
--- a/core/java/android/app/FragmentTransaction.java
+++ b/core/java/android/app/FragmentTransaction.java
@@ -315,14 +315,22 @@ public abstract class FragmentTransaction {
* in this transaction may have been optimized out due to the presence of a subsequent
* fragment transaction in the batch.
*
- * <p><code>postOnCommit</code> may not be used with transactions
+ *
+ * <p>If a transaction is committed using {@link #commitAllowingStateLoss()} this runnable
+ * may be executed when the FragmentManager is in a state where new transactions may not
+ * be committed without allowing state loss.</p>
+ *
+ * <p><code>runOnCommit</code> may not be used with transactions
* {@link #addToBackStack(String) added to the back stack} as Runnables cannot be persisted
- * with back stack state.</p>
+ * with back stack state. {@link IllegalStateException} will be thrown if
+ * {@link #addToBackStack(String)} has been previously called for this transaction
+ * or if it is called after a call to <code>runOnCommit</code>.</p>
*
* @param runnable Runnable to add
* @return this FragmentTransaction
+ * @throws IllegalStateException if {@link #addToBackStack(String)} has been called
*/
- public abstract FragmentTransaction postOnCommit(Runnable runnable);
+ public abstract FragmentTransaction runOnCommit(Runnable runnable);
/**
* Schedules a commit of this transaction. The commit does