Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright (C) 2011 The Android Open Source Project
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *      http://www.apache.org/licenses/LICENSE-2.0
    *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package android.support.v4.app;
  
  import android.os.Bundle;
  import android.os.Looper;
  import android.os.Parcel;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  
  import java.util.Arrays;
  import java.util.List;

Static library support version of the framework's android.app.FragmentManager. Used to write apps that run on platforms prior to Android 3.0. When running on Android 3.0 or above, this implementation is still used; it does not try to switch to the framework's implementation. See the framework SDK documentation for a class overview.

Your activity must derive from FragmentActivity to use this.

  
  public abstract class FragmentManager {
    
Representation of an entry on the fragment back stack, as created with FragmentTransaction.addToBackStack(). Entries can later be retrieved with FragmentManager.getBackStackEntry().

Note that you should never hold on to a BackStackEntry object; the identifier as returned by getId() is the only thing that will be persisted across activity instances.

  
      public interface BackStackEntry {
        
Return the unique identifier for the entry. This is the only representation of the entry that will persist across activity instances.
  
          public int getId();

        
Get the name that was supplied to FragmentTransaction.addToBackStack(String) when creating this entry.
  
          public String getName();

        
Return the full bread crumb title resource identifier for the entry, or 0 if it does not have one.
  
          public int getBreadCrumbTitleRes();

        
Return the short bread crumb title resource identifier for the entry, or 0 if it does not have one.
  
          public int getBreadCrumbShortTitleRes();

        
Return the full bread crumb title for the entry, or null if it does not have one.
 
         public CharSequence getBreadCrumbTitle();

        
Return the short bread crumb title for the entry, or null if it does not have one.
 
         public CharSequence getBreadCrumbShortTitle();
     }

    
Interface to watch for changes to the back stack.
 
     public interface OnBackStackChangedListener {
        
Called whenever the contents of the back stack change.
 
         public void onBackStackChanged();
     }

    
Start a series of edit operations on the Fragments associated with this FragmentManager.

Note: A fragment transaction can only be created/committed prior to an activity saving its state. If you try to commit a transaction after FragmentActivity.onSaveInstanceState() (and prior to a following FragmentActivity.onStart or FragmentActivity.onResume(), you will get an error. This is because the framework takes care of saving your current fragments in the state, and if changes are made after the state is saved then they will be lost.

 
     public abstract FragmentTransaction beginTransaction();

    

Hide:
-- remove once prebuilts are in.
 
     @Deprecated
     public FragmentTransaction openTransaction() {
         return beginTransaction();
     }
    
    
After a FragmentTransaction is committed with FragmentTransaction.commit(), it is scheduled to be executed asynchronously on the process's main thread. If you want to immediately executing any such pending operations, you can call this function (only from the main thread) to do so. Note that all callbacks and other related behavior will be done from within this call, so be careful about where this is called from.

Returns:
Returns true if there were any pending transactions to be executed.
 
     public abstract boolean executePendingTransactions();

    
Finds a fragment that was identified by the given id either when inflated from XML or as the container ID when added in a transaction. This first searches through fragments that are currently added to the manager's activity; if no such fragment is found, then all fragments currently on the back stack associated with this ID are searched.

Returns:
The fragment if found or null otherwise.
 
     public abstract Fragment findFragmentById(int id);

    
Finds a fragment that was identified by the given tag either when inflated from XML or as supplied when added in a transaction. This first searches through fragments that are currently added to the manager's activity; if no such fragment is found, then all fragments currently on the back stack are searched.

Returns:
The fragment if found or null otherwise.
 
     public abstract Fragment findFragmentByTag(String tag);

    
Flag for popBackStack(java.lang.String,int) and popBackStack(int,int): If set, and the name or ID of a back stack entry has been supplied, then all matching entries will be consumed until one that doesn't match is found or the bottom of the stack is reached. Otherwise, all entries up to but not including that entry will be removed.
 
     public static final int POP_BACK_STACK_INCLUSIVE = 1<<0;

    
Pop the top state off the back stack. Returns true if there was one to pop, else false. This function is asynchronous -- it enqueues the request to pop, but the action will not be performed until the application returns to its event loop.
 
     public abstract void popBackStack();

    
Like popBackStack(), but performs the operation immediately inside of the call. This is like calling executePendingTransactions() afterwards.

Returns:
Returns true if there was something popped, else false.
 
     public abstract boolean popBackStackImmediate();

    
Pop the last fragment transition from the manager's fragment back stack. If there is nothing to pop, false is returned. This function is asynchronous -- it enqueues the request to pop, but the action will not be performed until the application returns to its event loop.

Parameters:
name If non-null, this is the name of a previous back state to look for; if found, all states up to that state will be popped. The POP_BACK_STACK_INCLUSIVE flag can be used to control whether the named state itself is popped. If null, only the top state is popped.
flags Either 0 or POP_BACK_STACK_INCLUSIVE.
 
     public abstract void popBackStack(String nameint flags);

    
Like popBackStack(java.lang.String,int), but performs the operation immediately inside of the call. This is like calling executePendingTransactions() afterwards.

Returns:
Returns true if there was something popped, else false.
 
     public abstract boolean popBackStackImmediate(String nameint flags);

    
Pop all back stack states up to the one with the given identifier. This function is asynchronous -- it enqueues the request to pop, but the action will not be performed until the application returns to its event loop.

Parameters:
id Identifier of the stated to be popped. If no identifier exists, false is returned. The identifier is the number returned by FragmentTransaction.commit(). The POP_BACK_STACK_INCLUSIVE flag can be used to control whether the named state itself is popped.
flags Either 0 or POP_BACK_STACK_INCLUSIVE.
 
     public abstract void popBackStack(int idint flags);

    
Like popBackStack(int,int), but performs the operation immediately inside of the call. This is like calling executePendingTransactions() afterwards.

Returns:
Returns true if there was something popped, else false.
 
     public abstract boolean popBackStackImmediate(int idint flags);

    
Return the number of entries currently in the back stack.
 
     public abstract int getBackStackEntryCount();

    
Return the BackStackEntry at index index in the back stack; entries start index 0 being the bottom of the stack.
 
     public abstract BackStackEntry getBackStackEntryAt(int index);

    
Add a new listener for changes to the fragment back stack.
 
     public abstract void addOnBackStackChangedListener(OnBackStackChangedListener listener);

    
 
     public abstract void removeOnBackStackChangedListener(OnBackStackChangedListener listener);

    
Put a reference to a fragment in a Bundle. This Bundle can be persisted as saved state, and when later restoring getFragment(android.os.Bundle,java.lang.String) will return the current instance of the same fragment.

Parameters:
bundle The bundle in which to put the fragment reference.
key The name of the entry in the bundle.
fragment The Fragment whose reference is to be stored.
 
     public abstract void putFragment(Bundle bundleString keyFragment fragment);

    
Retrieve the current Fragment instance for a reference previously placed with putFragment(android.os.Bundle,java.lang.String,android.support.v4.app.Fragment).

Parameters:
bundle The bundle from which to retrieve the fragment reference.
key The name of the entry in the bundle.
Returns:
Returns the current Fragment instance that is associated with the given reference.
 
     public abstract Fragment getFragment(Bundle bundleString key);

    
Get a list of all fragments that have been added to the fragment manager.

Returns:
The list of all fragments or null if none.
Hide:
 
     public abstract List<FragmentgetFragments();

    
Save the current instance state of the given Fragment. This can be used later when creating a new instance of the Fragment and adding it to the fragment manager, to have it create itself to match the current state returned here. Note that there are limits on how this can be used:
  • The Fragment must currently be attached to the FragmentManager.
  • A new Fragment created using this saved state must be the same class type as the Fragment it was created from.
  • The saved state can not contain dependencies on other fragments -- that is it can't use putFragment(android.os.Bundle,java.lang.String,android.support.v4.app.Fragment) to store a fragment reference because that reference may not be valid when this saved state is later used. Likewise the Fragment's target and result code are not included in this state.

Parameters:
f The Fragment whose state is to be saved.
Returns:
The generated state. This will be null if there was no interesting state created by the fragment.
 
     public abstract Fragment.SavedState saveFragmentInstanceState(Fragment f);

    
Print the FragmentManager's state into the given stream.

Parameters:
prefix Text to print at the front of each line.
fd The raw file descriptor that the dump is being sent to.
writer A PrintWriter to which the dump is to be set.
args Additional arguments to the dump request.
 
     public abstract void dump(String prefixFileDescriptor fdPrintWriter writerString[] args);

    
Control whether the framework's internal fragment manager debugging logs are turned on. If enabled, you will see output in logcat as the framework performs fragment operations.
 
     public static void enableDebugLogging(boolean enabled) {
         . = enabled;
     }
 }
 
 final class FragmentManagerState implements Parcelable {
     int[] mAdded;
     
     public FragmentManagerState() {
     }
     
     public FragmentManagerState(Parcel in) {
          = in.createIntArray();
     }
     
     public int describeContents() {
         return 0;
     }
 
     public void writeToParcel(Parcel destint flags) {
         dest.writeTypedArray(flags);
         dest.writeIntArray();
         dest.writeTypedArray(flags);
     }
     
     public static final Parcelable.Creator<FragmentManagerStateCREATOR
             = new Parcelable.Creator<FragmentManagerState>() {
         public FragmentManagerState createFromParcel(Parcel in) {
             return new FragmentManagerState(in);
         }
         
         public FragmentManagerState[] newArray(int size) {
             return new FragmentManagerState[size];
         }
     };
 }

Callbacks from FragmentManagerImpl to its container.
 
 interface FragmentContainer {
     public View findViewById(int id);
 }

Container for fragments associated with an activity.
 
 final class FragmentManagerImpl extends FragmentManager {
     static boolean DEBUG = false;
     static final String TAG = "FragmentManager";
     
     static final boolean HONEYCOMB = .... >= 11;
 
     static final String TARGET_REQUEST_CODE_STATE_TAG = "android:target_req_state";
     static final String TARGET_STATE_TAG = "android:target_state";
     static final String VIEW_STATE_TAG = "android:view_state";
     static final String USER_VISIBLE_HINT_TAG = "android:user_visible_hint";
 
     Runnable[] mTmpActions;
     boolean mExecutingActions;
     
     
     // Must be accessed while locked.
 
 
     int mCurState = .;
     Fragment mParent;
     
     boolean mNeedMenuInvalidate;
     boolean mStateSaved;
     boolean mDestroyed;
     boolean mHavePendingDeferredStart;
     
     // Temporary vars for state save and restore.
     Bundle mStateBundle = null;
     SparseArray<ParcelablemStateArray = null;
     
     Runnable mExecCommit = new Runnable() {
         @Override
         public void run() {
             execPendingActions();
         }
     };
 
     private void throwException(RuntimeException ex) {
         Log.e(ex.getMessage());
         Log.e("Activity state:");
         LogWriter logw = new LogWriter();
         PrintWriter pw = new PrintWriter(logw);
         if ( != null) {
             try {
                 .dump("  "nullpwnew String[] { });
             } catch (Exception e) {
                 Log.e("Failed dumping state"e);
             }
         } else {
             try {
                 dump("  "nullpwnew String[] { });
             } catch (Exception e) {
                 Log.e("Failed dumping state"e);
             }
         }
         throw ex;
     }
 
     @Override
         return new BackStackRecord(this);
     }
 
     @Override
     public boolean executePendingTransactions() {
         return execPendingActions();
     }
 
     @Override
     public void popBackStack() {
         enqueueAction(new Runnable() {
             @Override public void run() {
                 popBackStackState(.null, -1, 0);
             }
         }, false);
     }
 
     @Override
     public boolean popBackStackImmediate() {
         checkStateLoss();
         executePendingTransactions();
         return popBackStackState(.null, -1, 0);
     }
 
     @Override
     public void popBackStack(final String namefinal int flags) {
         enqueueAction(new Runnable() {
             @Override public void run() {
                 popBackStackState(.name, -1, flags);
             }
         }, false);
     }
 
     @Override
     public boolean popBackStackImmediate(String nameint flags) {
         checkStateLoss();
         executePendingTransactions();
         return popBackStackState(.name, -1, flags);
     }
 
     @Override
     public void popBackStack(final int idfinal int flags) {
         if (id < 0) {
             throw new IllegalArgumentException("Bad id: " + id);
         }
         enqueueAction(new Runnable() {
             @Override public void run() {
                 popBackStackState(.nullidflags);
             }
         }, false);
     }
 
     @Override
     public boolean popBackStackImmediate(int idint flags) {
         checkStateLoss();
         executePendingTransactions();
         if (id < 0) {
             throw new IllegalArgumentException("Bad id: " + id);
         }
         return popBackStackState(.nullidflags);
     }
 
     @Override
     public int getBackStackEntryCount() {
         return  != null ? .size() : 0;
     }
 
     @Override
     public BackStackEntry getBackStackEntryAt(int index) {
         return .get(index);
     }
 
     @Override
     public void addOnBackStackChangedListener(OnBackStackChangedListener listener) {
         if ( == null) {
         }
         .add(listener);
     }
 
     @Override
         if ( != null) {
             .remove(listener);
         }
     }
 
     @Override
     public void putFragment(Bundle bundleString keyFragment fragment) {
         if (fragment.mIndex < 0) {
             throwException(new IllegalStateException("Fragment " + fragment
                     + " is not currently in the FragmentManager"));
         }
         bundle.putInt(keyfragment.mIndex);
     }
 
     @Override
     public Fragment getFragment(Bundle bundleString key) {
         int index = bundle.getInt(key, -1);
         if (index == -1) {
             return null;
         }
         if (index >= .size()) {
             throwException(new IllegalStateException("Fragement no longer exists for key "
                     + key + ": index " + index));
         }
         Fragment f = .get(index);
         if (f == null) {
             throwException(new IllegalStateException("Fragement no longer exists for key "
                     + key + ": index " + index));
         }
         return f;
     }
 
     @Override
     public List<FragmentgetFragments() {
         return ;
     }
 
     @Override
     public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) {
         if (fragment.mIndex < 0) {
             throwExceptionnew IllegalStateException("Fragment " + fragment
                     + " is not currently in the FragmentManager"));
         }
         if (fragment.mState > .) {
             Bundle result = saveFragmentBasicState(fragment);
             return result != null ? new Fragment.SavedState(result) : null;
         }
         return null;
     }
 
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder(128);
         sb.append("FragmentManager{");
         sb.append(Integer.toHexString(System.identityHashCode(this)));
         sb.append(" in ");
         if ( != null) {
             DebugUtils.buildShortClassTag(sb);
         } else {
             DebugUtils.buildShortClassTag(sb);
         }
         sb.append("}}");
         return sb.toString();
     }
 
     @Override
     public void dump(String prefixFileDescriptor fdPrintWriter writerString[] args) {
         String innerPrefix = prefix + "    ";
 
         int N;
         if ( != null) {
             N = .size();
             if (N > 0) {
                 writer.print(prefix); writer.print("Active Fragments in ");
                         writer.print(Integer.toHexString(System.identityHashCode(this)));
                         writer.println(":");
                 for (int i=0; i<Ni++) {
                     Fragment f = .get(i);
                     writer.print(prefix); writer.print("  #"); writer.print(i);
                             writer.print(": "); writer.println(f);
                     if (f != null) {
                         f.dump(innerPrefixfdwriterargs);
                     }
                 }
             }
         }
 
         if ( != null) {
             N = .size();
             if (N > 0) {
                 writer.print(prefix); writer.println("Added Fragments:");
                 for (int i=0; i<Ni++) {
                     Fragment f = .get(i);
                     writer.print(prefix); writer.print("  #"); writer.print(i);
                             writer.print(": "); writer.println(f.toString());
                 }
             }
         }
 
         if ( != null) {
             N = .size();
             if (N > 0) {
                 writer.print(prefix); writer.println("Fragments Created Menus:");
                 for (int i=0; i<Ni++) {
                     Fragment f = .get(i);
                     writer.print(prefix); writer.print("  #"); writer.print(i);
                             writer.print(": "); writer.println(f.toString());
                 }
             }
         }
 
         if ( != null) {
             N = .size();
             if (N > 0) {
                 writer.print(prefix); writer.println("Back Stack:");
                 for (int i=0; i<Ni++) {
                     BackStackRecord bs = .get(i);
                     writer.print(prefix); writer.print("  #"); writer.print(i);
                             writer.print(": "); writer.println(bs.toString());
                     bs.dump(innerPrefixfdwriterargs);
                 }
             }
         }
 
         synchronized (this) {
             if ( != null) {
                 N = .size();
                 if (N > 0) {
                     writer.print(prefix); writer.println("Back Stack Indices:");
                     for (int i=0; i<Ni++) {
                         BackStackRecord bs = .get(i);
                         writer.print(prefix); writer.print("  #"); writer.print(i);
                                 writer.print(": "); writer.println(bs);
                     }
                 }
             }
 
             if ( != null && .size() > 0) {
                 writer.print(prefix); writer.print("mAvailBackStackIndices: ");
                         writer.println(Arrays.toString(.toArray()));
             }
         }
 
         if ( != null) {
             N = .size();
             if (N > 0) {
                 writer.print(prefix); writer.println("Pending Actions:");
                 for (int i=0; i<Ni++) {
                     Runnable r = .get(i);
                     writer.print(prefix); writer.print("  #"); writer.print(i);
                             writer.print(": "); writer.println(r);
                 }
             }
         }
 
         writer.print(prefix); writer.println("FragmentManager misc state:");
         writer.print(prefix); writer.print("  mActivity="); writer.println();
         writer.print(prefix); writer.print("  mContainer="); writer.println();
         if ( != null) {
             writer.print(prefix); writer.print("  mParent="); writer.println();
         }
         writer.print(prefix); writer.print("  mCurState="); writer.print();
                 writer.print(" mStateSaved="); writer.print();
                 writer.print(" mDestroyed="); writer.println();
         if () {
             writer.print(prefix); writer.print("  mNeedMenuInvalidate=");
                     writer.println();
         }
         if ( != null) {
             writer.print(prefix); writer.print("  mNoTransactionsBecause=");
                     writer.println();
         }
         if ( != null && .size() > 0) {
             writer.print(prefix); writer.print("  mAvailIndices: ");
                     writer.println(Arrays.toString(.toArray()));
         }
     }
 
     static final Interpolator DECELERATE_QUINT = new DecelerateInterpolator(2.5f);
     static final Interpolator DECELERATE_CUBIC = new DecelerateInterpolator(1.5f);
     static final Interpolator ACCELERATE_QUINT = new AccelerateInterpolator(2.5f);
     static final Interpolator ACCELERATE_CUBIC = new AccelerateInterpolator(1.5f);
     
     static final int ANIM_DUR = 220;
     
     static Animation makeOpenCloseAnimation(Context contextfloat startScale,
             float endScalefloat startAlphafloat endAlpha) {
         AnimationSet set = new AnimationSet(false);
         ScaleAnimation scale = new ScaleAnimation(startScaleendScalestartScaleendScale,
                 ., .5f, ., .5f);
         scale.setInterpolator();
         scale.setDuration();
         set.addAnimation(scale);
         AlphaAnimation alpha = new AlphaAnimation(startAlphaendAlpha);
         alpha.setInterpolator();
         alpha.setDuration();
         set.addAnimation(alpha);
         return set;
     }
     
     static Animation makeFadeAnimation(Context contextfloat startfloat end) {
         AlphaAnimation anim = new AlphaAnimation(startend);
         anim.setInterpolator();
         anim.setDuration();
         return anim;
     }
     
     Animation loadAnimation(Fragment fragmentint transitboolean enter,
             int transitionStyle) {
         Animation animObj = fragment.onCreateAnimation(transitenter,
                 fragment.mNextAnim);
         if (animObj != null) {
             return animObj;
         }
         
         if (fragment.mNextAnim != 0) {
             Animation anim = AnimationUtils.loadAnimation(fragment.mNextAnim);
             if (anim != null) {
                 return anim;
             }
         }
         
         if (transit == 0) {
             return null;
         }
         
         int styleIndex = transitToStyleIndex(transitenter);
         if (styleIndex < 0) {
             return null;
         }
         
         switch (styleIndex) {
             case :
                 return makeOpenCloseAnimation(, 1.125f, 1.0f, 0, 1);
             case :
                 return makeOpenCloseAnimation(, 1.0f, .975f, 1, 0);
             case :
                 return makeOpenCloseAnimation(, .975f, 1.0f, 0, 1);
             case :
                 return makeOpenCloseAnimation(, 1.0f, 1.075f, 1, 0);
             case :
                 return makeFadeAnimation(, 0, 1);
             case :
                 return makeFadeAnimation(, 1, 0);
         }
         
         if (transitionStyle == 0 && .getWindow() != null) {
             transitionStyle = .getWindow().getAttributes().;
         }
         if (transitionStyle == 0) {
             return null;
         }
         
         //TypedArray attrs = mActivity.obtainStyledAttributes(transitionStyle,
         //        com.android.internal.R.styleable.FragmentAnimation);
         //int anim = attrs.getResourceId(styleIndex, 0);
         //attrs.recycle();
         
         //if (anim == 0) {
         //    return null;
         //}
         
         //return AnimatorInflater.loadAnimator(mActivity, anim);
         return null;
     }
     
     public void performPendingDeferredStart(Fragment f) {
         if (f.mDeferStart) {
             if () {
                 // Wait until we're done executing our pending transactions
                  = true;
                 return;
             }
             f.mDeferStart = false;
             moveToState(f, 0, 0, false);
         }
     }
 
     void moveToState(Fragment fint newStateint transitint transitionStyle,
             boolean keepActive) {
         // Fragments that are not currently added will sit in the onCreate() state.
         if ((!f.mAdded || f.mDetached) && newState > .) {
             newState = .;
         }
         if (f.mRemoving && newState > f.mState) {
             // While removing a fragment, we can't change it to a higher state.
             newState = f.mState;
         }
         // Defer start if requested; don't allow it to move to STARTED or higher
         // if it's not already started.
         if (f.mDeferStart && f.mState < . && newState > .) {
             newState = .;
         }
         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
                 // animation, move to whatever the final state should be once
                 // the animation is done, and then we can proceed from there.
                 f.mAnimatingAway = null;
                 moveToState(ff.mStateAfterAnimating, 0, 0, true);
             }
             switch (f.mState) {
                 case .:
                     if () Log.v("moveto CREATED: " + f);
                     if (f.mSavedFragmentState != null) {
                         f.mSavedViewState = f.mSavedFragmentState.getSparseParcelableArray(
                                 .);
                         f.mTarget = getFragment(f.mSavedFragmentState,
                                 .);
                         if (f.mTarget != null) {
                             f.mTargetRequestCode = f.mSavedFragmentState.getInt(
                                     ., 0);
                         }
                         f.mUserVisibleHint = f.mSavedFragmentState.getBoolean(
                                 .true);
                         if (!f.mUserVisibleHint) {
                             f.mDeferStart = true;
                             if (newState > .) {
                                 newState = .;
                             }
                         }
                     }
                     f.mActivity = ;
                     f.mParentFragment = ;
                     f.mFragmentManager =  != null
                             ? . : .;
                     f.mCalled = false;
                     f.onAttach();
                     if (!f.mCalled) {
                         throw new SuperNotCalledException("Fragment " + f
                                 + " did not call through to super.onAttach()");
                     }
                     if (f.mParentFragment == null) {
                         .onAttachFragment(f);
                     }
 
                     if (!f.mRetaining) {
                         f.performCreate(f.mSavedFragmentState);
                     }
                     f.mRetaining = false;
                     if (f.mFromLayout) {
                         // For fragments that are part of the content view
                         // layout, we need to instantiate the view immediately
                         // and the inflater will take care of adding it.
                         f.mView = f.performCreateView(f.getLayoutInflater(
                                 f.mSavedFragmentState), nullf.mSavedFragmentState);
                         if (f.mView != null) {
                             f.mInnerView = f.mView;
                             f.mView = NoSaveStateFrameLayout.wrap(f.mView);
                             if (f.mHiddenf.mView.setVisibility(.);
                             f.onViewCreated(f.mViewf.mSavedFragmentState);
                         } else {
                             f.mInnerView = null;
                         }
                     }
                 case .:
                     if (newState > .) {
                         if () Log.v("moveto ACTIVITY_CREATED: " + f);
                         if (!f.mFromLayout) {
                             ViewGroup container = null;
                             if (f.mContainerId != 0) {
                                 container = (ViewGroup).findViewById(f.mContainerId);
                                 if (container == null && !f.mRestored) {
                                     throwException(new IllegalArgumentException(
                                             "No view found for id 0x"
                                             + Integer.toHexString(f.mContainerId) + " ("
                                             + f.getResources().getResourceName(f.mContainerId)
                                             + ") for fragment " + f));
                                 }
                             }
                             f.mContainer = container;
                             f.mView = f.performCreateView(f.getLayoutInflater(
                                     f.mSavedFragmentState), containerf.mSavedFragmentState);
                             if (f.mView != null) {
                                 f.mInnerView = f.mView;
                                 f.mView = NoSaveStateFrameLayout.wrap(f.mView);
                                 if (container != null) {
                                     Animation anim = loadAnimation(ftransittrue,
                                             transitionStyle);
                                     if (anim != null) {
                                         f.mView.startAnimation(anim);
                                     }
                                     container.addView(f.mView);
                                 }
                                 if (f.mHiddenf.mView.setVisibility(.);
                                 f.onViewCreated(f.mViewf.mSavedFragmentState);
                             } else {
                                 f.mInnerView = null;
                             }
                         }
 
                         f.performActivityCreated(f.mSavedFragmentState);
                         if (f.mView != null) {
                             f.restoreViewState(f.mSavedFragmentState);
                         }
                         f.mSavedFragmentState = null;
                     }
                 case .:
                 case .:
                     if (newState > .) {
                         if () Log.v("moveto STARTED: " + f);
                         f.performStart();
                     }
                 case .:
                     if (newState > .) {
                         if () Log.v("moveto RESUMED: " + f);
                         f.mResumed = true;
                         f.performResume();
                         f.mSavedFragmentState = null;
                         f.mSavedViewState = null;
                     }
             }
         } else if (f.mState > newState) {
             switch (f.mState) {
                 case .:
                     if (newState < .) {
                         if () Log.v("movefrom RESUMED: " + f);
                         f.performPause();
                         f.mResumed = false;
                     }
                 case .:
                     if (newState < .) {
                         if () Log.v("movefrom STARTED: " + f);
                         f.performStop();
                     }
                 case .:
                     if (newState < .) {
                         if () Log.v("movefrom STOPPED: " + f);
                         f.performReallyStop();
                     }
                 case .:
                     if (newState < .) {
                         if () Log.v("movefrom ACTIVITY_CREATED: " + f);
                         if (f.mView != null) {
                             // Need to save the current view state if not
                             // done already.
                             if (!.isFinishing() && f.mSavedViewState == null) {
                                 saveFragmentViewState(f);
                             }
                         }
                         f.performDestroyView();
                         if (f.mView != null && f.mContainer != null) {
                             Animation anim = null;
                             if ( > . && !) {
                                 anim = loadAnimation(ftransitfalse,
                                         transitionStyle);
                            }
                            if (anim != null) {
                                final Fragment fragment = f;
                                f.mAnimatingAway = f.mView;
                                f.mStateAfterAnimating = newState;
                                anim.setAnimationListener(new AnimationListener() {
                                    @Override
                                    public void onAnimationEnd(Animation animation) {
                                        if (fragment.mAnimatingAway != null) {
                                            fragment.mAnimatingAway = null;
                                            moveToState(fragmentfragment.mStateAfterAnimating,
                                                    0, 0, false);
                                        }
                                    }
                                    @Override
                                    public void onAnimationRepeat(Animation animation) {
                                    }
                                    @Override
                                    public void onAnimationStart(Animation animation) {
                                    }
                                });
                                f.mView.startAnimation(anim);
                            }
                            f.mContainer.removeView(f.mView);
                        }
                        f.mContainer = null;
                        f.mView = null;
                        f.mInnerView = null;
                    }
                case .:
                    if (newState < .) {
                        if () {
                            if (f.mAnimatingAway != null) {
                                // The fragment's containing activity is
                                // being destroyed, but this fragment is
                                // currently animating away.  Stop the
                                // animation right now -- it is not needed,
                                // and we can't wait any more on destroying
                                // the fragment.
                                View v = f.mAnimatingAway;
                                f.mAnimatingAway = null;
                                v.clearAnimation();
                            }
                        }
                        if (f.mAnimatingAway != null) {
                            // We are waiting for the fragment's view to finish
                            // animating away.  Just make a note of the state
                            // the fragment now should move to once the animation
                            // is done.
                            f.mStateAfterAnimating = newState;
                            newState = .;
                        } else {
                            if () Log.v("movefrom CREATED: " + f);
                            if (!f.mRetaining) {
                                f.performDestroy();
                            }
                            f.mCalled = false;
                            f.onDetach();
                            if (!f.mCalled) {
                                throw new SuperNotCalledException("Fragment " + f
                                        + " did not call through to super.onDetach()");
                            }
                            if (!keepActive) {
                                if (!f.mRetaining) {
                                    makeInactive(f);
                                } else {
                                    f.mActivity = null;
                                    f.mFragmentManager = null;
                                }
                            }
                        }
                    }
            }
        }
        
        f.mState = newState;
    }
    
    void moveToState(Fragment f) {
        moveToState(f, 0, 0, false);
    }
    void moveToState(int newStateboolean always) {
        moveToState(newState, 0, 0, always);
    }
    
    void moveToState(int newStateint transitint transitStyleboolean always) {
        if ( == null && newState != .) {
            throw new IllegalStateException("No activity");
        }
        if (!always &&  == newState) {
            return;
        }
         = newState;
        if ( != null) {
            boolean loadersRunning = false;
            for (int i=0; i<.size(); i++) {
                Fragment f = .get(i);
                if (f != null) {
                    moveToState(fnewStatetransittransitStylefalse);
                    if (f.mLoaderManager != null) {
                        loadersRunning |= f.mLoaderManager.hasRunningLoaders();
                    }
                }
            }
            if (!loadersRunning) {
                startPendingDeferredFragments();
            }
            if ( &&  != null &&  == .) {
                .supportInvalidateOptionsMenu();
                 = false;
            }
        }
    }
        if ( == nullreturn;
        for (int i=0; i<.size(); i++) {
            Fragment f = .get(i);
            if (f != null) {
                performPendingDeferredStart(f);
            }
        }
    }
    
    void makeActive(Fragment f) {
        if (f.mIndex >= 0) {
            return;
        }
        
        if ( == null || .size() <= 0) {
            if ( == null) {
                 = new ArrayList<Fragment>();
            }
            f.setIndex(.size(), );
            .add(f);
            
        } else {
            f.setIndex(.remove(.size()-1), );
            .set(f.mIndexf);
        }
        if () Log.v("Allocated fragment index " + f);
    }
    
    void makeInactive(Fragment f) {
        if (f.mIndex < 0) {
            return;
        }
        
        if () Log.v("Freeing fragment index " + f);
        .set(f.mIndexnull);
        if ( == null) {
             = new ArrayList<Integer>();
        }
        .add(f.mIndex);
        .invalidateSupportFragment(f.mWho);
        f.initState();
    }
    
    public void addFragment(Fragment fragmentboolean moveToStateNow) {
        if ( == null) {
             = new ArrayList<Fragment>();
        }
        if () Log.v("add: " + fragment);
        makeActive(fragment);
        if (!fragment.mDetached) {
            if (.contains(fragment)) {