From e3a7f628c6d9fef42be24999b3137ebe5c6f3525 Mon Sep 17 00:00:00 2001
From: Dianne Hackborn This is called every time the fragment is inflated, even if it is
- * being inflated into a new instance with saved state. Because a fragment's
- * arguments are retained across instances, it may make no sense to re-parse
- * the attributes into new arguments. You may want to first check
- * {@link #getArguments()} and only parse the attributes if it returns null,
- * the assumption being that if it is non-null those are the same arguments
- * from the first time the fragment was inflated. (That said, you may want
- * to have layouts change for different configurations such as landscape
- * and portrait, which can have different attributes. If so, you will need
- * to re-parse the attributes each time this is called to generate new
- * arguments.)
Here is a typical implementation of a fragment that can take parameters + * both through attributes supplied here as well from {@link #getArguments()}:
+ * + * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java + * fragment} + * + *Note that parsing the XML attributes uses a "styleable" resource. The + * declaration for the styleable used here is:
+ * + * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments} * + *The fragment can then be declared within its activity's content layout + * through a tag like this:
+ * + * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes} + * + *This fragment can also be created dynamically from arguments given + * at runtime in the arguments Bundle; here is an example of doing so at + * creation of the containing activity:
+ * + * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java + * create} + * + * @param activity The Activity that is inflating this fragment. * @param attrs The attributes at the tag where the fragment is * being created. * @param savedInstanceState If the fragment is being re-created from * a previous saved state, this is the state. */ - public void onInflate(AttributeSet attrs, Bundle savedInstanceState) { + public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { + onInflate(attrs, savedInstanceState); mCalled = true; } diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java index d8d0a5b..ab60cf0 100644 --- a/core/java/android/app/FragmentManager.java +++ b/core/java/android/app/FragmentManager.java @@ -660,6 +660,12 @@ final class FragmentManagerImpl extends FragmentManager { } if (f.mState < newState) { + // For fragments that are created from a layout, when restoring from + // state we don't want to allow them to be created until they are + // being reloaded from the layout. + if (f.mFromLayout && !f.mInLayout) { + return; + } if (f.mAnimatingAway != null) { // The fragment is currently being animated... but! Now we // want to move our state back up. Give up on waiting for the -- cgit v1.1