FragmentManager.java revision 6252d78085a07c9d6bb4645a4e8086bf23b0a49a
1cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/*
2cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Copyright (C) 2011 The Android Open Source Project
3cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
4cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License");
5cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * you may not use this file except in compliance with the License.
6cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * You may obtain a copy of the License at
7cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
8cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *      http://www.apache.org/licenses/LICENSE-2.0
9cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn *
10cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Unless required by applicable law or agreed to in writing, software
11cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS,
12cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * See the License for the specific language governing permissions and
14cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * limitations under the License.
15cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
16cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
17cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpackage android.support.v4.app;
18cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
199277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackbornimport android.content.Context;
20cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration;
21cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle;
22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Handler;
23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Looper;
24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel;
25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable;
26cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.DebugUtils;
27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.LogWriter;
28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.Log;
29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray;
309277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackbornimport android.view.animation.AccelerateInterpolator;
319277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackbornimport android.view.animation.AlphaAnimation;
32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation;
339277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackbornimport android.view.animation.AnimationSet;
34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.AnimationUtils;
359277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackbornimport android.view.animation.DecelerateInterpolator;
369277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackbornimport android.view.animation.Interpolator;
379277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackbornimport android.view.animation.ScaleAnimation;
38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation.AnimationListener;
39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu;
40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater;
41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem;
42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View;
43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ViewGroup;
44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor;
46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter;
47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.util.ArrayList;
48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.util.Arrays;
493a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brownimport java.util.List;
50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/**
52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.FragmentManager}.
53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0.  When running
54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try
559dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * to switch to the framework's implementation.  See the framework {@link FragmentManager}
56cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview.
579dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main *
589dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * <p>Your activity must derive from {@link FragmentActivity} to use this. From such an activity,
599dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * you can acquire the {@link FragmentManager} by calling
609dcd2e58138ca4eb4b18f80b50e8979329e859d6Scott Main * {@link FragmentActivity#getSupportFragmentManager}.
61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic abstract class FragmentManager {
63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Representation of an entry on the fragment back stack, as created
65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * with {@link FragmentTransaction#addToBackStack(String)
66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * FragmentTransaction.addToBackStack()}.  Entries can later be
67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * retrieved with {@link FragmentManager#getBackStackEntryAt(int)
68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * FragmentManager.getBackStackEntry()}.
69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
70cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Note that you should never hold on to a BackStackEntry object;
71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the identifier as returned by {@link #getId} is the only thing that
72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will be persisted across activity instances.
73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public interface BackStackEntry {
75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        /**
76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * Return the unique identifier for the entry.  This is the only
77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * representation of the entry that will persist across activity
78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * instances.
79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         */
80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public int getId();
81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
82cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        /**
832a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn         * Get the name that was supplied to
842a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn         * {@link FragmentTransaction#addToBackStack(String)
852a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn         * FragmentTransaction.addToBackStack(String)} when creating this entry.
862a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn         */
872a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        public String getName();
882a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
892a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        /**
90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * Return the full bread crumb title resource identifier for the entry,
91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * or 0 if it does not have one.
92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         */
93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public int getBreadCrumbTitleRes();
94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        /**
96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * Return the short bread crumb title resource identifier for the entry,
97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * or 0 if it does not have one.
98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         */
99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public int getBreadCrumbShortTitleRes();
100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        /**
102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * Return the full bread crumb title for the entry, or null if it
103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * does not have one.
104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         */
105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public CharSequence getBreadCrumbTitle();
106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        /**
108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * Return the short bread crumb title for the entry, or null if it
109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * does not have one.
110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         */
111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public CharSequence getBreadCrumbShortTitle();
112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Interface to watch for changes to the back stack.
116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public interface OnBackStackChangedListener {
118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        /**
119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         * Called whenever the contents of the back stack change.
120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn         */
121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public void onBackStackChanged();
122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Start a series of edit operations on the Fragments associated with
126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * this FragmentManager.
127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Note: A fragment transaction can only be created/committed prior
129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to an activity saving its state.  If you try to commit a transaction
130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link FragmentActivity#onSaveInstanceState FragmentActivity.onSaveInstanceState()}
131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * (and prior to a following {@link FragmentActivity#onStart FragmentActivity.onStart}
132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * or {@link FragmentActivity#onResume FragmentActivity.onResume()}, you will get an error.
133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is because the framework takes care of saving your current fragments
134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the state, and if changes are made after the state is saved then they
135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will be lost.</p>
136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract FragmentTransaction beginTransaction();
138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /** @hide -- remove once prebuilts are in. */
140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Deprecated
141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentTransaction openTransaction() {
142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return beginTransaction();
143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * After a {@link FragmentTransaction} is committed with
147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link FragmentTransaction#commit FragmentTransaction.commit()}, it
148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is scheduled to be executed asynchronously on the process's main thread.
149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * If you want to immediately executing any such pending operations, you
150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can call this function (only from the main thread) to do so.  Note that
151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * all callbacks and other related behavior will be done from within this
152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * call, so be careful about where this is called from.
153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns true if there were any pending transactions to be
155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * executed.
156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract boolean executePendingTransactions();
158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Finds a fragment that was identified by the given id either when inflated
161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * from XML or as the container ID when added in a transaction.  This first
162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * searches through fragments that are currently added to the manager's
163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity; if no such fragment is found, then all fragments currently
164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * on the back stack associated with this ID are searched.
165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return The fragment if found or null otherwise.
166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract Fragment findFragmentById(int id);
168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Finds a fragment that was identified by the given tag either when inflated
171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * from XML or as supplied when added in a transaction.  This first
172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * searches through fragments that are currently added to the manager's
173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity; if no such fragment is found, then all fragments currently
174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * on the back stack are searched.
175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return The fragment if found or null otherwise.
176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract Fragment findFragmentByTag(String tag);
178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Flag for {@link #popBackStack(String, int)}
181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and {@link #popBackStack(int, int)}: If set, and the name or ID of
182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a back stack entry has been supplied, then all matching entries will
183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be consumed until one that doesn't match is found or the bottom of
184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the stack is reached.  Otherwise, all entries up to but not including that entry
185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will be removed.
186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static final int POP_BACK_STACK_INCLUSIVE = 1<<0;
188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Pop the top state off the back stack.  Returns true if there was one
191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to pop, else false.  This function is asynchronous -- it enqueues the
192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * request to pop, but the action will not be performed until the application
193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * returns to its event loop.
194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract void popBackStack();
196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Like {@link #popBackStack()}, but performs the operation immediately
199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inside of the call.  This is like calling {@link #executePendingTransactions()}
200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * afterwards.
201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns true if there was something popped, else false.
202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract boolean popBackStackImmediate();
204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Pop the last fragment transition from the manager's fragment
207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * back stack.  If there is nothing to pop, false is returned.
208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This function is asynchronous -- it enqueues the
209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * request to pop, but the action will not be performed until the application
210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * returns to its event loop.
211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param name If non-null, this is the name of a previous back state
213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to look for; if found, all states up to that state will be popped.  The
214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #POP_BACK_STACK_INCLUSIVE} flag can be used to control whether
215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the named state itself is popped. If null, only the top state is popped.
216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}.
217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract void popBackStack(String name, int flags);
219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Like {@link #popBackStack(String, int)}, but performs the operation immediately
222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inside of the call.  This is like calling {@link #executePendingTransactions()}
223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * afterwards.
224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns true if there was something popped, else false.
225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract boolean popBackStackImmediate(String name, int flags);
227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Pop all back stack states up to the one with the given identifier.
230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This function is asynchronous -- it enqueues the
231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * request to pop, but the action will not be performed until the application
232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * returns to its event loop.
233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param id Identifier of the stated to be popped. If no identifier exists,
235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * false is returned.
236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The identifier is the number returned by
237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link FragmentTransaction#commit() FragmentTransaction.commit()}.  The
238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #POP_BACK_STACK_INCLUSIVE} flag can be used to control whether
239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the named state itself is popped.
240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param flags Either 0 or {@link #POP_BACK_STACK_INCLUSIVE}.
241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract void popBackStack(int id, int flags);
243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Like {@link #popBackStack(int, int)}, but performs the operation immediately
246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inside of the call.  This is like calling {@link #executePendingTransactions()}
247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * afterwards.
248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns true if there was something popped, else false.
249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract boolean popBackStackImmediate(int id, int flags);
251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the number of entries currently in the back stack.
254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract int getBackStackEntryCount();
256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the BackStackEntry at index <var>index</var> in the back stack;
259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * entries start index 0 being the bottom of the stack.
260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract BackStackEntry getBackStackEntryAt(int index);
262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Add a new listener for changes to the fragment back stack.
265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract void addOnBackStackChangedListener(OnBackStackChangedListener listener);
267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Remove a listener that was previously added with
270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #addOnBackStackChangedListener(OnBackStackChangedListener)}.
271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract void removeOnBackStackChangedListener(OnBackStackChangedListener listener);
273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Put a reference to a fragment in a Bundle.  This Bundle can be
276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * persisted as saved state, and when later restoring
277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #getFragment(Bundle, String)} will return the current
278cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * instance of the same fragment.
279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param bundle The bundle in which to put the fragment reference.
281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param key The name of the entry in the bundle.
282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fragment The Fragment whose reference is to be stored.
283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract void putFragment(Bundle bundle, String key, Fragment fragment);
285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Retrieve the current Fragment instance for a reference previously
288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * placed with {@link #putFragment(Bundle, String, Fragment)}.
289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param bundle The bundle from which to retrieve the fragment reference.
291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param key The name of the entry in the bundle.
292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns the current Fragment instance that is associated with
293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the given reference.
294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract Fragment getFragment(Bundle bundle, String key);
296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
2983a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown     * Get a list of all fragments that have been added to the fragment manager.
2993a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown     *
3003a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown     * @return The list of all fragments or null if none.
3013a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown     * @hide
3023a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown     */
3033a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    public abstract List<Fragment> getFragments();
3043a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
3053a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    /**
3065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Save the current instance state of the given Fragment.  This can be
3075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * used later when creating a new instance of the Fragment and adding
3085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * it to the fragment manager, to have it create itself to match the
3095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * current state returned here.  Note that there are limits on how
3105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * this can be used:
3115c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
3125c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * <ul>
3135c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * <li>The Fragment must currently be attached to the FragmentManager.
3145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * <li>A new Fragment created using this saved state must be the same class
3155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * type as the Fragment it was created from.
3165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * <li>The saved state can not contain dependencies on other fragments --
3175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * that is it can't use {@link #putFragment(Bundle, String, Fragment)} to
3185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * store a fragment reference because that reference may not be valid when
3195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * this saved state is later used.  Likewise the Fragment's target and
3205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * result code are not included in this state.
3215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * </ul>
3225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
3235c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param f The Fragment whose state is to be saved.
3245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @return The generated state.  This will be null if there was no
3255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * interesting state created by the fragment.
3265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
3275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public abstract Fragment.SavedState saveFragmentInstanceState(Fragment f);
3285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
33001df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler     * Returns true if the final {@link android.app.Activity#onDestroy() Activity.onDestroy()}
33101df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler     * call has been made on the FragmentManager's Activity, so this instance is now dead.
33201df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler     */
33301df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler    public abstract boolean isDestroyed();
33401df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler
33501df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler    /**
336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Print the FragmentManager's state into the given stream.
337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param prefix Text to print at the front of each line.
339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fd The raw file descriptor that the dump is being sent to.
340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param writer A PrintWriter to which the dump is to be set.
341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args Additional arguments to the dump request.
342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public abstract void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args);
344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Control whether the framework's internal fragment manager debugging
347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * logs are turned on.  If enabled, you will see output in logcat as
348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the framework performs fragment operations.
349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static void enableDebugLogging(boolean enabled) {
351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        FragmentManagerImpl.DEBUG = enabled;
352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class FragmentManagerState implements Parcelable {
356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    FragmentState[] mActive;
357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int[] mAdded;
358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    BackStackState[] mBackStack;
359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentManagerState() {
361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentManagerState(Parcel in) {
364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActive = in.createTypedArray(FragmentState.CREATOR);
365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mAdded = in.createIntArray();
366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mBackStack = in.createTypedArray(BackStackState.CREATOR);
367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public int describeContents() {
370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return 0;
371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void writeToParcel(Parcel dest, int flags) {
374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeTypedArray(mActive, flags);
375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeIntArray(mAdded);
376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeTypedArray(mBackStack, flags);
377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static final Parcelable.Creator<FragmentManagerState> CREATOR
380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            = new Parcelable.Creator<FragmentManagerState>() {
381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentManagerState createFromParcel(Parcel in) {
382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentManagerState(in);
383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentManagerState[] newArray(int size) {
386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentManagerState[size];
387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    };
389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/**
3920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn * Callbacks from FragmentManagerImpl to its container.
3930adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn */
3940adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborninterface FragmentContainer {
3950adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    public View findViewById(int id);
3960adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn}
3970adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
3980adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn/**
399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Container for fragments associated with an activity.
400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
401461b48b4588ac21b97aa40553f04222c2c0344e7Chris Banesfinal class FragmentManagerImpl extends FragmentManager {
402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static boolean DEBUG = false;
403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final String TAG = "FragmentManager";
404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
405681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn    static final boolean HONEYCOMB = android.os.Build.VERSION.SDK_INT >= 11;
406681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn
407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final String TARGET_REQUEST_CODE_STATE_TAG = "android:target_req_state";
408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final String TARGET_STATE_TAG = "android:target_state";
409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final String VIEW_STATE_TAG = "android:view_state";
41079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    static final String USER_VISIBLE_HINT_TAG = "android:user_visible_hint";
411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<Runnable> mPendingActions;
413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Runnable[] mTmpActions;
414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mExecutingActions;
415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<Fragment> mActive;
417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<Fragment> mAdded;
418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<Integer> mAvailIndices;
419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<BackStackRecord> mBackStack;
420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<Fragment> mCreatedMenus;
421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Must be accessed while locked.
423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<BackStackRecord> mBackStackIndices;
424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<Integer> mAvailBackStackIndices;
425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<OnBackStackChangedListener> mBackStackChangeListeners;
427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mCurState = Fragment.INITIALIZING;
429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    FragmentActivity mActivity;
4300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    FragmentContainer mContainer;
4310adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    Fragment mParent;
432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mNeedMenuInvalidate;
434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mStateSaved;
435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mDestroyed;
436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mNoTransactionsBecause;
43779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    boolean mHavePendingDeferredStart;
438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Temporary vars for state save and restore.
440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mStateBundle = null;
441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    SparseArray<Parcelable> mStateArray = null;
442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Runnable mExecCommit = new Runnable() {
444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        @Override
445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public void run() {
446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            execPendingActions();
447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    };
449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
45013fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn    private void throwException(RuntimeException ex) {
45113fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn        Log.e(TAG, ex.getMessage());
452ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn        Log.e(TAG, "Activity state:");
45313fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn        LogWriter logw = new LogWriter(TAG);
45413fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn        PrintWriter pw = new PrintWriter(logw);
45513fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn        if (mActivity != null) {
456ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn            try {
45713fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                mActivity.dump("  ", null, pw, new String[] { });
458ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn            } catch (Exception e) {
459ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn                Log.e(TAG, "Failed dumping state", e);
460ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn            }
461ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn        } else {
462ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn            try {
46313fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                dump("  ", null, pw, new String[] { });
464ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn            } catch (Exception e) {
46513fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                Log.e(TAG, "Failed dumping state", e);
466ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn            }
467ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn        }
46813fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn        throw ex;
469ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn    }
470ec9fb2522d42d1ff73ddffa12b318d925c10ab18Dianne Hackborn
471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentTransaction beginTransaction() {
473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return new BackStackRecord(this);
474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean executePendingTransactions() {
478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return execPendingActions();
479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void popBackStack() {
483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        enqueueAction(new Runnable() {
484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            @Override public void run() {
485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                popBackStackState(mActivity.mHandler, null, -1, 0);
486cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }, false);
488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean popBackStackImmediate() {
492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        checkStateLoss();
493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        executePendingTransactions();
494cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return popBackStackState(mActivity.mHandler, null, -1, 0);
495cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
496cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
497cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
498cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void popBackStack(final String name, final int flags) {
499cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        enqueueAction(new Runnable() {
500cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            @Override public void run() {
501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                popBackStackState(mActivity.mHandler, name, -1, flags);
502cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }, false);
504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean popBackStackImmediate(String name, int flags) {
508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        checkStateLoss();
509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        executePendingTransactions();
510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return popBackStackState(mActivity.mHandler, name, -1, flags);
511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void popBackStack(final int id, final int flags) {
515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (id < 0) {
516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalArgumentException("Bad id: " + id);
517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        enqueueAction(new Runnable() {
519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            @Override public void run() {
520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                popBackStackState(mActivity.mHandler, null, id, flags);
521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }, false);
523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean popBackStackImmediate(int id, int flags) {
527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        checkStateLoss();
528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        executePendingTransactions();
529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (id < 0) {
530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalArgumentException("Bad id: " + id);
531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return popBackStackState(mActivity.mHandler, null, id, flags);
533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public int getBackStackEntryCount() {
537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mBackStack != null ? mBackStack.size() : 0;
538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public BackStackEntry getBackStackEntryAt(int index) {
542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mBackStack.get(index);
543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void addOnBackStackChangedListener(OnBackStackChangedListener listener) {
547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mBackStackChangeListeners == null) {
548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mBackStackChangeListeners = new ArrayList<OnBackStackChangedListener>();
549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mBackStackChangeListeners.add(listener);
551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void removeOnBackStackChangedListener(OnBackStackChangedListener listener) {
555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mBackStackChangeListeners != null) {
556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mBackStackChangeListeners.remove(listener);
557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void putFragment(Bundle bundle, String key, Fragment fragment) {
562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (fragment.mIndex < 0) {
56313fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn            throwException(new IllegalStateException("Fragment " + fragment
56413fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                    + " is not currently in the FragmentManager"));
565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        bundle.putInt(key, fragment.mIndex);
567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment getFragment(Bundle bundle, String key) {
571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        int index = bundle.getInt(key, -1);
572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (index == -1) {
573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return null;
574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (index >= mActive.size()) {
5762b336307cf98ca5142db6736812178293d47c500Cyril Mottier            throwException(new IllegalStateException("Fragment no longer exists for key "
57713fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                    + key + ": index " + index));
578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        Fragment f = mActive.get(index);
580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (f == null) {
5812b336307cf98ca5142db6736812178293d47c500Cyril Mottier            throwException(new IllegalStateException("Fragment no longer exists for key "
58213fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                    + key + ": index " + index));
583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return f;
585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
5883a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    public List<Fragment> getFragments() {
5893a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown        return mActive;
5903a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    }
5913a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown
5923a1a7fff9873abbf8097c96f7654a459bf34f223Jeff Brown    @Override
5935c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public Fragment.SavedState saveFragmentInstanceState(Fragment fragment) {
5945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (fragment.mIndex < 0) {
59513fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn            throwException( new IllegalStateException("Fragment " + fragment
59613fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                    + " is not currently in the FragmentManager"));
5975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
5985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (fragment.mState > Fragment.INITIALIZING) {
5995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            Bundle result = saveFragmentBasicState(fragment);
6005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            return result != null ? new Fragment.SavedState(result) : null;
6015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
6025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        return null;
6035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
6045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
6055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    @Override
60601df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler    public boolean isDestroyed() {
60701df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler        return mDestroyed;
60801df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler    }
60901df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler
61001df737703cceecc6b3a319ca0ee0bd64415f1cfTony Mantler    @Override
611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public String toString() {
612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        StringBuilder sb = new StringBuilder(128);
613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append("FragmentManager{");
614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(Integer.toHexString(System.identityHashCode(this)));
615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append(" in ");
6160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mParent != null) {
6170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            DebugUtils.buildShortClassTag(mParent, sb);
6180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        } else {
6190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            DebugUtils.buildShortClassTag(mActivity, sb);
6200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
621cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append("}}");
622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return sb.toString();
623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        String innerPrefix = prefix + "    ";
628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        int N;
630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActive != null) {
631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            N = mActive.size();
632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (N > 0) {
633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(prefix); writer.print("Active Fragments in ");
634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        writer.print(Integer.toHexString(System.identityHashCode(this)));
635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        writer.println(":");
636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                for (int i=0; i<N; i++) {
637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    Fragment f = mActive.get(i);
638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(prefix); writer.print("  #"); writer.print(i);
639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            writer.print(": "); writer.println(f);
640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (f != null) {
641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.dump(innerPrefix, fd, writer, args);
642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAdded != null) {
648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            N = mAdded.size();
649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (N > 0) {
650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(prefix); writer.println("Added Fragments:");
651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                for (int i=0; i<N; i++) {
652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    Fragment f = mAdded.get(i);
653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(prefix); writer.print("  #"); writer.print(i);
654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            writer.print(": "); writer.println(f.toString());
655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mCreatedMenus != null) {
660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            N = mCreatedMenus.size();
661cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (N > 0) {
662cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(prefix); writer.println("Fragments Created Menus:");
663cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                for (int i=0; i<N; i++) {
664cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    Fragment f = mCreatedMenus.get(i);
665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(prefix); writer.print("  #"); writer.print(i);
666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            writer.print(": "); writer.println(f.toString());
667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mBackStack != null) {
672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            N = mBackStack.size();
673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (N > 0) {
674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(prefix); writer.println("Back Stack:");
675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                for (int i=0; i<N; i++) {
676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    BackStackRecord bs = mBackStack.get(i);
677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(prefix); writer.print("  #"); writer.print(i);
678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            writer.print(": "); writer.println(bs.toString());
679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    bs.dump(innerPrefix, fd, writer, args);
680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        synchronized (this) {
685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mBackStackIndices != null) {
686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                N = mBackStackIndices.size();
687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (N > 0) {
688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(prefix); writer.println("Back Stack Indices:");
689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    for (int i=0; i<N; i++) {
690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        BackStackRecord bs = mBackStackIndices.get(i);
691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        writer.print(prefix); writer.print("  #"); writer.print(i);
692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                writer.print(": "); writer.println(bs);
693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mAvailBackStackIndices != null && mAvailBackStackIndices.size() > 0) {
698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(prefix); writer.print("mAvailBackStackIndices: ");
699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        writer.println(Arrays.toString(mAvailBackStackIndices.toArray()));
700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mPendingActions != null) {
704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            N = mPendingActions.size();
705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (N > 0) {
706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(prefix); writer.println("Pending Actions:");
707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                for (int i=0; i<N; i++) {
708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    Runnable r = mPendingActions.get(i);
709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(prefix); writer.print("  #"); writer.print(i);
710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            writer.print(": "); writer.println(r);
711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.println("FragmentManager misc state:");
7160adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        writer.print(prefix); writer.print("  mActivity="); writer.println(mActivity);
7170adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        writer.print(prefix); writer.print("  mContainer="); writer.println(mContainer);
7180adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        if (mParent != null) {
7190adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            writer.print(prefix); writer.print("  mParent="); writer.println(mParent);
7200adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        }
721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("  mCurState="); writer.print(mCurState);
722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mStateSaved="); writer.print(mStateSaved);
723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mDestroyed="); writer.println(mDestroyed);
724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mNeedMenuInvalidate) {
725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("  mNeedMenuInvalidate=");
726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mNeedMenuInvalidate);
727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mNoTransactionsBecause != null) {
729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("  mNoTransactionsBecause=");
730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mNoTransactionsBecause);
731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAvailIndices != null && mAvailIndices.size() > 0) {
733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("  mAvailIndices: ");
734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(Arrays.toString(mAvailIndices.toArray()));
735cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
736cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
737cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
7389277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    static final Interpolator DECELERATE_QUINT = new DecelerateInterpolator(2.5f);
7399277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    static final Interpolator DECELERATE_CUBIC = new DecelerateInterpolator(1.5f);
7409277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    static final Interpolator ACCELERATE_QUINT = new AccelerateInterpolator(2.5f);
7419277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    static final Interpolator ACCELERATE_CUBIC = new AccelerateInterpolator(1.5f);
7429277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
7439277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    static final int ANIM_DUR = 220;
7449277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
7459277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    static Animation makeOpenCloseAnimation(Context context, float startScale,
7469277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            float endScale, float startAlpha, float endAlpha) {
7479277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        AnimationSet set = new AnimationSet(false);
7489277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        ScaleAnimation scale = new ScaleAnimation(startScale, endScale, startScale, endScale,
7499277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
7509277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        scale.setInterpolator(DECELERATE_QUINT);
7519277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        scale.setDuration(ANIM_DUR);
7529277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        set.addAnimation(scale);
7539277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        AlphaAnimation alpha = new AlphaAnimation(startAlpha, endAlpha);
7549277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        alpha.setInterpolator(DECELERATE_CUBIC);
7559277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        alpha.setDuration(ANIM_DUR);
7569277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        set.addAnimation(alpha);
7579277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        return set;
7589277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    }
7599277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
7609277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    static Animation makeFadeAnimation(Context context, float start, float end) {
7619277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        AlphaAnimation anim = new AlphaAnimation(start, end);
7629277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        anim.setInterpolator(DECELERATE_CUBIC);
7639277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        anim.setDuration(ANIM_DUR);
7649277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        return anim;
7659277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    }
7669277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
7679277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    Animation loadAnimation(Fragment fragment, int transit, boolean enter,
768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            int transitionStyle) {
7699277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        Animation animObj = fragment.onCreateAnimation(transit, enter,
770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                fragment.mNextAnim);
771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (animObj != null) {
772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return animObj;
773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (fragment.mNextAnim != 0) {
776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Animation anim = AnimationUtils.loadAnimation(mActivity, fragment.mNextAnim);
777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (anim != null) {
778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                return anim;
779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (transit == 0) {
783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return null;
784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        int styleIndex = transitToStyleIndex(transit, enter);
787cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (styleIndex < 0) {
788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return null;
789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
7919277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        switch (styleIndex) {
7929277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            case ANIM_STYLE_OPEN_ENTER:
7939277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                return makeOpenCloseAnimation(mActivity, 1.125f, 1.0f, 0, 1);
7949277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            case ANIM_STYLE_OPEN_EXIT:
7959277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                return makeOpenCloseAnimation(mActivity, 1.0f, .975f, 1, 0);
7969277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            case ANIM_STYLE_CLOSE_ENTER:
7979277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                return makeOpenCloseAnimation(mActivity, .975f, 1.0f, 0, 1);
7989277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            case ANIM_STYLE_CLOSE_EXIT:
7999277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                return makeOpenCloseAnimation(mActivity, 1.0f, 1.075f, 1, 0);
8009277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            case ANIM_STYLE_FADE_ENTER:
8019277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                return makeFadeAnimation(mActivity, 0, 1);
8029277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            case ANIM_STYLE_FADE_EXIT:
8039277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                return makeFadeAnimation(mActivity, 1, 0);
8049277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn        }
8059277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (transitionStyle == 0 && mActivity.getWindow() != null) {
807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            transitionStyle = mActivity.getWindow().getAttributes().windowAnimations;
808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (transitionStyle == 0) {
810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return null;
811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //TypedArray attrs = mActivity.obtainStyledAttributes(transitionStyle,
814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //        com.android.internal.R.styleable.FragmentAnimation);
815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //int anim = attrs.getResourceId(styleIndex, 0);
816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //attrs.recycle();
817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //if (anim == 0) {
819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //    return null;
820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //}
821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //return AnimatorInflater.loadAnimator(mActivity, anim);
823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
826abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    public void performPendingDeferredStart(Fragment f) {
827abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        if (f.mDeferStart) {
82879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            if (mExecutingActions) {
82979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                // Wait until we're done executing our pending transactions
83079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                mHavePendingDeferredStart = true;
83179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                return;
83279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            }
833abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            f.mDeferStart = false;
8345506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn            moveToState(f, mCurState, 0, 0, false);
835abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        }
836abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
837abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
8385506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn    void moveToState(Fragment f, int newState, int transit, int transitionStyle,
8395506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn            boolean keepActive) {
840cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Fragments that are not currently added will sit in the onCreate() state.
84174c671b3b67000bf16b4865a8d361344310dccbeDianne Hackborn        if ((!f.mAdded || f.mDetached) && newState > Fragment.CREATED) {
842cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            newState = Fragment.CREATED;
843cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
8442c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn        if (f.mRemoving && newState > f.mState) {
8452c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn            // While removing a fragment, we can't change it to a higher state.
8462c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn            newState = f.mState;
8472c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn        }
8486cafd27a3c89dfed10d7e226dc6168307513d4a6Adam Powell        // Defer start if requested; don't allow it to move to STARTED or higher
8496cafd27a3c89dfed10d7e226dc6168307513d4a6Adam Powell        // if it's not already started.
8506cafd27a3c89dfed10d7e226dc6168307513d4a6Adam Powell        if (f.mDeferStart && f.mState < Fragment.STARTED && newState > Fragment.STOPPED) {
851abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            newState = Fragment.STOPPED;
852abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        }
853cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (f.mState < newState) {
8549277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            // For fragments that are created from a layout, when restoring from
8559277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            // state we don't want to allow them to be created until they are
8569277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            // being reloaded from the layout.
8579277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            if (f.mFromLayout && !f.mInLayout) {
8589277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                return;
8599277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn            }
860cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (f.mAnimatingAway != null) {
861cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // The fragment is currently being animated...  but!  Now we
862cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // want to move our state back up.  Give up on waiting for the
863cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // animation, move to whatever the final state should be once
864cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // the animation is done, and then we can proceed from there.
865cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mAnimatingAway = null;
8665506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                moveToState(f, f.mStateAfterAnimating, 0, 0, true);
867cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            switch (f.mState) {
869cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.INITIALIZING:
870cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (DEBUG) Log.v(TAG, "moveto CREATED: " + f);
871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (f.mSavedFragmentState != null) {
872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mSavedViewState = f.mSavedFragmentState.getSparseParcelableArray(
873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                FragmentManagerImpl.VIEW_STATE_TAG);
874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mTarget = getFragment(f.mSavedFragmentState,
875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                FragmentManagerImpl.TARGET_STATE_TAG);
876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (f.mTarget != null) {
877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mTargetRequestCode = f.mSavedFragmentState.getInt(
878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG, 0);
879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
88079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                        f.mUserVisibleHint = f.mSavedFragmentState.getBoolean(
88179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                                FragmentManagerImpl.USER_VISIBLE_HINT_TAG, true);
88279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                        if (!f.mUserVisibleHint) {
88379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                            f.mDeferStart = true;
88479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                            if (newState > Fragment.STOPPED) {
88579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                                newState = Fragment.STOPPED;
88679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                            }
88779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                        }
888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    f.mActivity = mActivity;
8900adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    f.mParentFragment = mParent;
8910adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    f.mFragmentManager = mParent != null
8920adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                            ? mParent.mChildFragmentManager : mActivity.mFragments;
893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    f.mCalled = false;
894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    f.onAttach(mActivity);
895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (!f.mCalled) {
896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        throw new SuperNotCalledException("Fragment " + f
897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                + " did not call through to super.onAttach()");
898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
8990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    if (f.mParentFragment == null) {
9000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        mActivity.onAttachFragment(f);
9010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    }
9020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (!f.mRetaining) {
9040adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        f.performCreate(f.mSavedFragmentState);
905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
906cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    f.mRetaining = false;
907cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (f.mFromLayout) {
908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        // For fragments that are part of the content view
909cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        // layout, we need to instantiate the view immediately
910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        // and the inflater will take care of adding it.
9110adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        f.mView = f.performCreateView(f.getLayoutInflater(
9120adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                                f.mSavedFragmentState), null, f.mSavedFragmentState);
913cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (f.mView != null) {
914cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mInnerView = f.mView;
915cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mView = NoSaveStateFrameLayout.wrap(f.mView);
916715a71e5f73cbc33f307cbd3625db8f889a05c1aDianne Hackborn                            if (f.mHidden) f.mView.setVisibility(View.GONE);
917e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                            f.onViewCreated(f.mView, f.mSavedFragmentState);
918cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        } else {
919cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mInnerView = null;
920cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
921cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
922cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.CREATED:
923cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (newState > Fragment.CREATED) {
924e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                        if (DEBUG) Log.v(TAG, "moveto ACTIVITY_CREATED: " + f);
925cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (!f.mFromLayout) {
926cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            ViewGroup container = null;
927cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (f.mContainerId != 0) {
9280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                                container = (ViewGroup)mContainer.findViewById(f.mContainerId);
929cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                if (container == null && !f.mRestored) {
93013fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                    throwException(new IllegalArgumentException(
93113fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                            "No view found for id 0x"
93213fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                            + Integer.toHexString(f.mContainerId) + " ("
93313fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                            + f.getResources().getResourceName(f.mContainerId)
93413fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                            + ") for fragment " + f));
935cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                }
936cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
937cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mContainer = container;
9380adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                            f.mView = f.performCreateView(f.getLayoutInflater(
9390adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                                    f.mSavedFragmentState), container, f.mSavedFragmentState);
940cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (f.mView != null) {
941cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                f.mInnerView = f.mView;
942cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                f.mView = NoSaveStateFrameLayout.wrap(f.mView);
943cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                if (container != null) {
9449277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                                    Animation anim = loadAnimation(f, transit, true,
945cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                            transitionStyle);
946cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    if (anim != null) {
947cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                        f.mView.startAnimation(anim);
948cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    }
949cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    container.addView(f.mView);
950cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                }
951715a71e5f73cbc33f307cbd3625db8f889a05c1aDianne Hackborn                                if (f.mHidden) f.mView.setVisibility(View.GONE);
952e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                                f.onViewCreated(f.mView, f.mSavedFragmentState);
953cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            } else {
954cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                f.mInnerView = null;
955cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
956cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
9570adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
9580adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        f.performActivityCreated(f.mSavedFragmentState);
959e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                        if (f.mView != null) {
9600adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                            f.restoreViewState(f.mSavedFragmentState);
961e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                        }
962cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mSavedFragmentState = null;
963cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
964cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.ACTIVITY_CREATED:
965e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                case Fragment.STOPPED:
966e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                    if (newState > Fragment.STOPPED) {
967cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (DEBUG) Log.v(TAG, "moveto STARTED: " + f);
9689c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn                        f.performStart();
969cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
970cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.STARTED:
971cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (newState > Fragment.STARTED) {
972cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (DEBUG) Log.v(TAG, "moveto RESUMED: " + f);
973cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mResumed = true;
9740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        f.performResume();
9754e6647fe2551985f33407acd712a4942b090207aDianne Hackborn                        f.mSavedFragmentState = null;
9764e6647fe2551985f33407acd712a4942b090207aDianne Hackborn                        f.mSavedViewState = null;
977cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
979cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } else if (f.mState > newState) {
980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            switch (f.mState) {
981cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.RESUMED:
982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (newState < Fragment.RESUMED) {
983cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (DEBUG) Log.v(TAG, "movefrom RESUMED: " + f);
9840adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        f.performPause();
985cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mResumed = false;
986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
987cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.STARTED:
988cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (newState < Fragment.STARTED) {
989cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (DEBUG) Log.v(TAG, "movefrom STARTED: " + f);
990cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.performStop();
991cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
992e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                case Fragment.STOPPED:
993218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn                    if (newState < Fragment.STOPPED) {
994218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn                        if (DEBUG) Log.v(TAG, "movefrom STOPPED: " + f);
995218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn                        f.performReallyStop();
996218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn                    }
997cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.ACTIVITY_CREATED:
998cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (newState < Fragment.ACTIVITY_CREATED) {
999e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                        if (DEBUG) Log.v(TAG, "movefrom ACTIVITY_CREATED: " + f);
1000cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (f.mView != null) {
1001cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            // Need to save the current view state if not
1002cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            // done already.
1003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (!mActivity.isFinishing() && f.mSavedViewState == null) {
1004cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                saveFragmentViewState(f);
1005cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
1006cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
10079c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn                        f.performDestroyView();
1008cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (f.mView != null && f.mContainer != null) {
1009cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            Animation anim = null;
1010cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (mCurState > Fragment.INITIALIZING && !mDestroyed) {
10119277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                                anim = loadAnimation(f, transit, false,
1012cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                        transitionStyle);
1013cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
1014cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (anim != null) {
1015cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                final Fragment fragment = f;
1016cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                f.mAnimatingAway = f.mView;
1017cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                f.mStateAfterAnimating = newState;
1018cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                anim.setAnimationListener(new AnimationListener() {
1019cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    @Override
1020cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    public void onAnimationEnd(Animation animation) {
1021cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                        if (fragment.mAnimatingAway != null) {
1022cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                            fragment.mAnimatingAway = null;
1023cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                            moveToState(fragment, fragment.mStateAfterAnimating,
10245506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                                                    0, 0, false);
1025cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                        }
1026cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    }
1027cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    @Override
1028cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    public void onAnimationRepeat(Animation animation) {
1029cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    }
1030cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    @Override
1031cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    public void onAnimationStart(Animation animation) {
1032cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    }
1033cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                });
10349277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                                f.mView.startAnimation(anim);
1035cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
1036cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mContainer.removeView(f.mView);
1037cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
1038cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mContainer = null;
1039cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mView = null;
1040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mInnerView = null;
1041cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1042cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                case Fragment.CREATED:
1043cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (newState < Fragment.CREATED) {
1044cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (mDestroyed) {
1045cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (f.mAnimatingAway != null) {
1046cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                // The fragment's containing activity is
1047cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                // being destroyed, but this fragment is
1048cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                // currently animating away.  Stop the
1049cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                // animation right now -- it is not needed,
1050cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                // and we can't wait any more on destroying
1051cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                // the fragment.
1052cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                View v = f.mAnimatingAway;
1053cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                f.mAnimatingAway = null;
1054cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                v.clearAnimation();
1055cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
1056cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
1057cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (f.mAnimatingAway != null) {
1058cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            // We are waiting for the fragment's view to finish
1059cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            // animating away.  Just make a note of the state
1060cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            // the fragment now should move to once the animation
1061cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            // is done.
1062cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mStateAfterAnimating = newState;
10632c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                            newState = Fragment.CREATED;
1064cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        } else {
1065cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (DEBUG) Log.v(TAG, "movefrom CREATED: " + f);
1066cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (!f.mRetaining) {
10670adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                                f.performDestroy();
1068cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
1069cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1070cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.mCalled = false;
1071cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            f.onDetach();
1072cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            if (!f.mCalled) {
1073cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                throw new SuperNotCalledException("Fragment " + f
1074cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                        + " did not call through to super.onDetach()");
1075cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            }
10765506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                            if (!keepActive) {
10775506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                                if (!f.mRetaining) {
10785506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                                    makeInactive(f);
10795506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                                } else {
10805506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                                    f.mActivity = null;
10816252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn                                    f.mParentFragment = null;
10825506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                                    f.mFragmentManager = null;
10836252d78085a07c9d6bb4645a4e8086bf23b0a49aTim Kilbourn                                    f.mChildFragmentManager = null;
10845506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                                }
10852c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                            }
1086cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
1087cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1088cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1089cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1090cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1091cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        f.mState = newState;
1092cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1093cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1094cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void moveToState(Fragment f) {
10955506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn        moveToState(f, mCurState, 0, 0, false);
1096cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1097cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1098cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void moveToState(int newState, boolean always) {
1099cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        moveToState(newState, 0, 0, always);
1100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void moveToState(int newState, int transit, int transitStyle, boolean always) {
1103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null && newState != Fragment.INITIALIZING) {
1104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("No activity");
1105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
11060adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!always && mCurState == newState) {
1108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return;
1109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
11100adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCurState = newState;
1112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActive != null) {
1113abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            boolean loadersRunning = false;
1114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mActive.size(); i++) {
1115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mActive.get(i);
1116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null) {
11175506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                    moveToState(f, newState, transit, transitStyle, false);
1118abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell                    if (f.mLoaderManager != null) {
1119abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell                        loadersRunning |= f.mLoaderManager.hasRunningLoaders();
1120abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell                    }
1121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1124abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            if (!loadersRunning) {
1125abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell                startPendingDeferredFragments();
1126abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            }
1127abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
11282a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (mNeedMenuInvalidate && mActivity != null && mCurState == Fragment.RESUMED) {
1129681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn                mActivity.supportInvalidateOptionsMenu();
1130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mNeedMenuInvalidate = false;
1131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1134abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
1135abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    void startPendingDeferredFragments() {
11361199ae7067cdf8cf3eb30c057a61ae71a0aea1e5Adam Powell        if (mActive == null) return;
11371199ae7067cdf8cf3eb30c057a61ae71a0aea1e5Adam Powell
1138abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        for (int i=0; i<mActive.size(); i++) {
1139abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            Fragment f = mActive.get(i);
1140abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            if (f != null) {
1141abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell                performPendingDeferredStart(f);
1142abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            }
1143abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        }
1144abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
1145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void makeActive(Fragment f) {
1147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (f.mIndex >= 0) {
1148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return;
1149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAvailIndices == null || mAvailIndices.size() <= 0) {
1152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mActive == null) {
1153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mActive = new ArrayList<Fragment>();
1154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
11550adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            f.setIndex(mActive.size(), mParent);
1156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mActive.add(f);
1157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } else {
11590adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            f.setIndex(mAvailIndices.remove(mAvailIndices.size()-1), mParent);
1160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mActive.set(f.mIndex, f);
1161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1162be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn        if (DEBUG) Log.v(TAG, "Allocated fragment index " + f);
1163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void makeInactive(Fragment f) {
1166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (f.mIndex < 0) {
1167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return;
1168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1170be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn        if (DEBUG) Log.v(TAG, "Freeing fragment index " + f);
1171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActive.set(f.mIndex, null);
1172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAvailIndices == null) {
1173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mAvailIndices = new ArrayList<Integer>();
1174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mAvailIndices.add(f.mIndex);
11760adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mActivity.invalidateSupportFragment(f.mWho);
11779c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        f.initState();
1178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void addFragment(Fragment fragment, boolean moveToStateNow) {
1181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAdded == null) {
1182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mAdded = new ArrayList<Fragment>();
1183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (DEBUG) Log.v(TAG, "add: " + fragment);
1185e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        makeActive(fragment);
1186e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        if (!fragment.mDetached) {
11873a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn            if (mAdded.contains(fragment)) {
11883a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                throw new IllegalStateException("Fragment already added: " + fragment);
11893a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn            }
1190e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            mAdded.add(fragment);
1191e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            fragment.mAdded = true;
1192e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            fragment.mRemoving = false;
11932a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (fragment.mHasMenu && fragment.mMenuVisible) {
1194e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                mNeedMenuInvalidate = true;
1195e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            }
1196e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            if (moveToStateNow) {
1197e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                moveToState(fragment);
1198e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            }
1199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void removeFragment(Fragment fragment, int transition, int transitionStyle) {
1203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (DEBUG) Log.v(TAG, "remove: " + fragment + " nesting=" + fragment.mBackStackNesting);
1204e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        final boolean inactive = !fragment.isInBackStack();
1205e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        if (!fragment.mDetached || inactive) {
1206464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn            if (mAdded != null) {
1207464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn                mAdded.remove(fragment);
1208464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn            }
12092a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (fragment.mHasMenu && fragment.mMenuVisible) {
1210e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                mNeedMenuInvalidate = true;
1211e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            }
1212e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            fragment.mAdded = false;
1213e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            fragment.mRemoving = true;
1214e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            moveToState(fragment, inactive ? Fragment.INITIALIZING : Fragment.CREATED,
12155506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                    transition, transitionStyle, false);
1216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void hideFragment(Fragment fragment, int transition, int transitionStyle) {
1220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (DEBUG) Log.v(TAG, "hide: " + fragment);
1221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!fragment.mHidden) {
1222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            fragment.mHidden = true;
1223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (fragment.mView != null) {
1224495efcad8c8865e3e6f14e4ea3d79cfb1d2410f9Alexander Mironov                Animation anim = loadAnimation(fragment, transition, false,
1225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        transitionStyle);
1226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (anim != null) {
1227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    fragment.mView.startAnimation(anim);
1228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                fragment.mView.setVisibility(View.GONE);
1230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
12312a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
1232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mNeedMenuInvalidate = true;
1233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            fragment.onHiddenChanged(true);
1235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void showFragment(Fragment fragment, int transition, int transitionStyle) {
1239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (DEBUG) Log.v(TAG, "show: " + fragment);
1240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (fragment.mHidden) {
1241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            fragment.mHidden = false;
1242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (fragment.mView != null) {
12439277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                Animation anim = loadAnimation(fragment, transition, true,
1244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        transitionStyle);
1245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (anim != null) {
1246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    fragment.mView.startAnimation(anim);
1247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                fragment.mView.setVisibility(View.VISIBLE);
1249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
12502a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
1251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mNeedMenuInvalidate = true;
1252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            fragment.onHiddenChanged(false);
1254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1257e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    public void detachFragment(Fragment fragment, int transition, int transitionStyle) {
1258e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        if (DEBUG) Log.v(TAG, "detach: " + fragment);
1259e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        if (!fragment.mDetached) {
1260e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            fragment.mDetached = true;
1261e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            if (fragment.mAdded) {
1262e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                // We are not already in back stack, so need to remove the fragment.
1263464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn                if (mAdded != null) {
12643a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                    if (DEBUG) Log.v(TAG, "remove from detach: " + fragment);
1265464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn                    mAdded.remove(fragment);
1266464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn                }
12672a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                if (fragment.mHasMenu && fragment.mMenuVisible) {
1268e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                    mNeedMenuInvalidate = true;
1269e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                }
1270e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                fragment.mAdded = false;
12715506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                moveToState(fragment, Fragment.CREATED, transition, transitionStyle, false);
1272e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            }
1273e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        }
1274e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
1275e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
1276e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    public void attachFragment(Fragment fragment, int transition, int transitionStyle) {
1277e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        if (DEBUG) Log.v(TAG, "attach: " + fragment);
1278e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        if (fragment.mDetached) {
1279e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            fragment.mDetached = false;
1280e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            if (!fragment.mAdded) {
1281464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn                if (mAdded == null) {
1282464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn                    mAdded = new ArrayList<Fragment>();
1283464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn                }
12843a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                if (mAdded.contains(fragment)) {
12853a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                    throw new IllegalStateException("Fragment already added: " + fragment);
12863a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                }
12873a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                if (DEBUG) Log.v(TAG, "add from attach: " + fragment);
1288e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                mAdded.add(fragment);
1289e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                fragment.mAdded = true;
12902a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                if (fragment.mHasMenu && fragment.mMenuVisible) {
1291e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                    mNeedMenuInvalidate = true;
1292e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                }
12935506618c80a292ac275d8b0c1046b446c7f58836Dianne Hackborn                moveToState(fragment, mCurState, transition, transitionStyle, false);
1294e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn            }
1295e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        }
1296e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
1297e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
1298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment findFragmentById(int id) {
1299464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
1300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            // First look through added fragments.
1301cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=mAdded.size()-1; i>=0; i--) {
1302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
1303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null && f.mFragmentId == id) {
1304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    return f;
1305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1307464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        }
1308464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mActive != null) {
1309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            // Now for any known fragment.
1310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=mActive.size()-1; i>=0; i--) {
1311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mActive.get(i);
1312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null && f.mFragmentId == id) {
1313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    return f;
1314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
1318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment findFragmentByTag(String tag) {
1321464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null && tag != null) {
1322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            // First look through added fragments.
1323cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=mAdded.size()-1; i>=0; i--) {
1324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
1325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null && tag.equals(f.mTag)) {
1326cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    return f;
1327cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1329464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        }
1330464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mActive != null && tag != null) {
1331cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            // Now for any known fragment.
1332cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=mActive.size()-1; i>=0; i--) {
1333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mActive.get(i);
1334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null && tag.equals(f.mTag)) {
1335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    return f;
1336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
1340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment findFragmentByWho(String who) {
1343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActive != null && who != null) {
1344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=mActive.size()-1; i>=0; i--) {
1345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mActive.get(i);
13460adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (f != null && (f=f.findFragmentByWho(who)) != null) {
1347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    return f;
1348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
1352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    private void checkStateLoss() {
1355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mStateSaved) {
1356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException(
1357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    "Can not perform this action after onSaveInstanceState");
1358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mNoTransactionsBecause != null) {
1360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException(
1361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    "Can not perform this action inside of " + mNoTransactionsBecause);
1362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1365ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette    /**
1366ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette     * Adds an action to the queue of pending actions.
1367ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette     *
1368ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette     * @param action the action to add
1369ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette     * @param allowStateLoss whether to allow loss of state information
1370ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette     * @throws IllegalStateException if the activity has been destroyed
1371ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette     */
1372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void enqueueAction(Runnable action, boolean allowStateLoss) {
1373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!allowStateLoss) {
1374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            checkStateLoss();
1375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        synchronized (this) {
1377ab6e5dbcc6e05994ebb4257478c54f54085b9aa6Alan Viverette            if (mDestroyed || mActivity == null) {
1378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                throw new IllegalStateException("Activity has been destroyed");
1379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mPendingActions == null) {
1381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mPendingActions = new ArrayList<Runnable>();
1382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mPendingActions.add(action);
1384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mPendingActions.size() == 1) {
1385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mActivity.mHandler.removeCallbacks(mExecCommit);
1386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mActivity.mHandler.post(mExecCommit);
1387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public int allocBackStackIndex(BackStackRecord bse) {
1392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        synchronized (this) {
1393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mAvailBackStackIndices == null || mAvailBackStackIndices.size() <= 0) {
1394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (mBackStackIndices == null) {
1395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mBackStackIndices = new ArrayList<BackStackRecord>();
1396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                int index = mBackStackIndices.size();
1398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (DEBUG) Log.v(TAG, "Setting back stack index " + index + " to " + bse);
1399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mBackStackIndices.add(bse);
1400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                return index;
1401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            } else {
1403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                int index = mAvailBackStackIndices.remove(mAvailBackStackIndices.size()-1);
1404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (DEBUG) Log.v(TAG, "Adding back stack index " + index + " with " + bse);
1405cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mBackStackIndices.set(index, bse);
1406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                return index;
1407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setBackStackIndex(int index, BackStackRecord bse) {
1412cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        synchronized (this) {
1413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mBackStackIndices == null) {
1414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mBackStackIndices = new ArrayList<BackStackRecord>();
1415cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            int N = mBackStackIndices.size();
1417cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (index < N) {
1418cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (DEBUG) Log.v(TAG, "Setting back stack index " + index + " to " + bse);
1419cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mBackStackIndices.set(index, bse);
1420cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            } else {
1421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                while (N < index) {
1422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mBackStackIndices.add(null);
1423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (mAvailBackStackIndices == null) {
1424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        mAvailBackStackIndices = new ArrayList<Integer>();
1425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (DEBUG) Log.v(TAG, "Adding available back stack index " + N);
1427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mAvailBackStackIndices.add(N);
1428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    N++;
1429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (DEBUG) Log.v(TAG, "Adding back stack index " + index + " with " + bse);
1431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mBackStackIndices.add(bse);
1432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void freeBackStackIndex(int index) {
1437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        synchronized (this) {
1438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mBackStackIndices.set(index, null);
1439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mAvailBackStackIndices == null) {
1440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mAvailBackStackIndices = new ArrayList<Integer>();
1441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (DEBUG) Log.v(TAG, "Freeing back stack index " + index);
1443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mAvailBackStackIndices.add(index);
1444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Only call from main thread!
1449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean execPendingActions() {
1451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mExecutingActions) {
1452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Recursive entry to executePendingTransactions");
1453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (Looper.myLooper() != mActivity.mHandler.getLooper()) {
1456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Must be called from main thread of process");
1457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        boolean didSomething = false;
1460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        while (true) {
1462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            int numActions;
1463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            synchronized (this) {
1465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (mPendingActions == null || mPendingActions.size() == 0) {
146679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                    break;
1467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                numActions = mPendingActions.size();
1470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (mTmpActions == null || mTmpActions.length < numActions) {
1471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mTmpActions = new Runnable[numActions];
1472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mPendingActions.toArray(mTmpActions);
1474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mPendingActions.clear();
1475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mActivity.mHandler.removeCallbacks(mExecCommit);
1476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mExecutingActions = true;
1479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<numActions; i++) {
1480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mTmpActions[i].run();
14819f491519261135d9de50b60c2182755ccb665bf5Jeff Sharkey                mTmpActions[i] = null;
1482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mExecutingActions = false;
1484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            didSomething = true;
1485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
148679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell
148779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        if (mHavePendingDeferredStart) {
148879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            boolean loadersRunning = false;
148979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            for (int i=0; i<mActive.size(); i++) {
149079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                Fragment f = mActive.get(i);
149179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                if (f != null && f.mLoaderManager != null) {
149279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                    loadersRunning |= f.mLoaderManager.hasRunningLoaders();
149379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                }
149479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            }
149579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            if (!loadersRunning) {
149679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                mHavePendingDeferredStart = false;
149779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                startPendingDeferredFragments();
149879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            }
149979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        }
150079398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        return didSomething;
1501cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
150279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell
1503cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void reportBackStackChanged() {
1504cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mBackStackChangeListeners != null) {
1505cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mBackStackChangeListeners.size(); i++) {
1506cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mBackStackChangeListeners.get(i).onBackStackChanged();
1507cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1508cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1509cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void addBackStackState(BackStackRecord state) {
1512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mBackStack == null) {
1513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mBackStack = new ArrayList<BackStackRecord>();
1514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mBackStack.add(state);
1516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        reportBackStackChanged();
1517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean popBackStackState(Handler handler, String name, int id, int flags) {
1520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mBackStack == null) {
1521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return false;
1522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (name == null && id < 0 && (flags&POP_BACK_STACK_INCLUSIVE) == 0) {
1524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            int last = mBackStack.size()-1;
1525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (last < 0) {
1526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                return false;
1527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            final BackStackRecord bss = mBackStack.remove(last);
1529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            bss.popFromBackStack(true);
1530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            reportBackStackChanged();
1531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } else {
1532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            int index = -1;
1533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (name != null || id >= 0) {
1534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // If a name or ID is specified, look for that place in
1535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // the stack.
1536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                index = mBackStack.size()-1;
1537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                while (index >= 0) {
1538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    BackStackRecord bss = mBackStack.get(index);
1539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (name != null && name.equals(bss.getName())) {
1540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        break;
1541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (id >= 0 && id == bss.mIndex) {
1543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        break;
1544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    index--;
1546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (index < 0) {
1548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    return false;
1549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if ((flags&POP_BACK_STACK_INCLUSIVE) != 0) {
1551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    index--;
1552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    // Consume all following entries that match.
1553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    while (index >= 0) {
1554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        BackStackRecord bss = mBackStack.get(index);
1555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if ((name != null && name.equals(bss.getName()))
1556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                || (id >= 0 && id == bss.mIndex)) {
1557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            index--;
1558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            continue;
1559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
1560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        break;
1561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (index == mBackStack.size()-1) {
1565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                return false;
1566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            final ArrayList<BackStackRecord> states
1568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    = new ArrayList<BackStackRecord>();
1569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=mBackStack.size()-1; i>index; i--) {
1570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                states.add(mBackStack.remove(i));
1571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            final int LAST = states.size()-1;
1573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<=LAST; i++) {
1574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (DEBUG) Log.v(TAG, "Popping back stack state: " + states.get(i));
1575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                states.get(i).popFromBackStack(i == LAST);
1576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            reportBackStackChanged();
1578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return true;
1580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1581cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1582cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ArrayList<Fragment> retainNonConfig() {
1583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        ArrayList<Fragment> fragments = null;
1584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActive != null) {
1585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mActive.size(); i++) {
1586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mActive.get(i);
1587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null && f.mRetainInstance) {
1588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (fragments == null) {
1589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        fragments = new ArrayList<Fragment>();
1590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    fragments.add(f);
1592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    f.mRetaining = true;
15932c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                    f.mTargetIndex = f.mTarget != null ? f.mTarget.mIndex : -1;
1594be2c79d9a5439922030d2a3846c81c61f0e16912Dianne Hackborn                    if (DEBUG) Log.v(TAG, "retainNonConfig: keeping retained " + f);
1595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1598cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return fragments;
1599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void saveFragmentViewState(Fragment f) {
1602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (f.mInnerView == null) {
1603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return;
1604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mStateArray == null) {
1606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mStateArray = new SparseArray<Parcelable>();
1607ea2c91b0198855073983b4a8437aa71cbd83872fDianne Hackborn        } else {
1608ea2c91b0198855073983b4a8437aa71cbd83872fDianne Hackborn            mStateArray.clear();
1609cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1610cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        f.mInnerView.saveHierarchyState(mStateArray);
1611cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mStateArray.size() > 0) {
1612cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            f.mSavedViewState = mStateArray;
1613cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mStateArray = null;
1614cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1615cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1616cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
16175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    Bundle saveFragmentBasicState(Fragment f) {
16185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        Bundle result = null;
16195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
16205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (mStateBundle == null) {
16215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mStateBundle = new Bundle();
16225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
16230adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        f.performSaveInstanceState(mStateBundle);
16245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (!mStateBundle.isEmpty()) {
16255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            result = mStateBundle;
16265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mStateBundle = null;
16275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
16285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
16295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (f.mView != null) {
16305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            saveFragmentViewState(f);
16315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
16325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (f.mSavedViewState != null) {
16335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            if (result == null) {
16345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                result = new Bundle();
16355c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
16365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            result.putSparseParcelableArray(
16375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                    FragmentManagerImpl.VIEW_STATE_TAG, f.mSavedViewState);
16385c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
163979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        if (!f.mUserVisibleHint) {
1640f4c0cf637ba73374a206cec26c09d4dfa4c1a364Jake Wharton            if (result == null) {
1641f4c0cf637ba73374a206cec26c09d4dfa4c1a364Jake Wharton                result = new Bundle();
1642f4c0cf637ba73374a206cec26c09d4dfa4c1a364Jake Wharton            }
164379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            // Only add this if it's not the default value
164479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell            result.putBoolean(FragmentManagerImpl.USER_VISIBLE_HINT_TAG, f.mUserVisibleHint);
164579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        }
16465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
16475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        return result;
16485c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
16495c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
1650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Parcelable saveAllState() {
1651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Make sure all pending operations have now been executed to get
1652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // our state update-to-date.
1653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        execPendingActions();
1654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1655681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn        if (HONEYCOMB) {
1656681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // As of Honeycomb, we save state after pausing.  Prior to that
1657681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // it is before pausing.  With fragments this is an issue, since
1658681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // there are many things you may do after pausing but before
1659681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // stopping that change the fragment state.  For those older
1660681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // devices, we will not at this point say that we have saved
1661681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // the state, so we will allow them to continue doing fragment
1662681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // transactions.  This retains the same semantics as Honeycomb,
1663681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // though you do have the risk of losing the very most recent state
1664681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            // if the process is killed...  we'll live with that.
1665681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn            mStateSaved = true;
1666681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn        }
1667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActive == null || mActive.size() <= 0) {
1669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return null;
1670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // First collect all active fragments.
1673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        int N = mActive.size();
1674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        FragmentState[] active = new FragmentState[N];
1675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        boolean haveFragments = false;
1676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        for (int i=0; i<N; i++) {
1677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Fragment f = mActive.get(i);
1678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (f != null) {
16791b913519b1c03b084779851e81db2e1a11eb0b0dDianne Hackborn                if (f.mIndex < 0) {
168013fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                    throwException(new IllegalStateException(
168113fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                            "Failure saving state: active " + f
168213fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                            + " has cleared index: " + f.mIndex));
16831b913519b1c03b084779851e81db2e1a11eb0b0dDianne Hackborn                }
16841b913519b1c03b084779851e81db2e1a11eb0b0dDianne Hackborn
1685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                haveFragments = true;
1686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                FragmentState fs = new FragmentState(f);
1688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                active[i] = fs;
1689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f.mState > Fragment.INITIALIZING && fs.mSavedFragmentState == null) {
16915c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                    fs.mSavedFragmentState = saveFragmentBasicState(f);
1692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (f.mTarget != null) {
1694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (f.mTarget.mIndex < 0) {
169513fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                            throwException(new IllegalStateException(
169613fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                    "Failure saving state: " + f
169713fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                    + " has target not in fragment manager: " + f.mTarget));
1698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
1699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (fs.mSavedFragmentState == null) {
1700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            fs.mSavedFragmentState = new Bundle();
1701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
1702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        putFragment(fs.mSavedFragmentState,
1703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                FragmentManagerImpl.TARGET_STATE_TAG, f.mTarget);
1704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        if (f.mTargetRequestCode != 0) {
1705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            fs.mSavedFragmentState.putInt(
1706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    FragmentManagerImpl.TARGET_REQUEST_CODE_STATE_TAG,
1707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                                    f.mTargetRequestCode);
1708cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        }
1709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                } else {
1712cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    fs.mSavedFragmentState = f.mSavedFragmentState;
1713cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1714cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1715cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (DEBUG) Log.v(TAG, "Saved state of " + f + ": "
1716cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        + fs.mSavedFragmentState);
1717cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1718cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1719cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1720cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!haveFragments) {
1721cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (DEBUG) Log.v(TAG, "saveAllState: no fragments!");
1722cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return null;
1723cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1724cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1725cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        int[] added = null;
1726cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        BackStackState[] backStack = null;
1727cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1728cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Build list of currently added fragments.
1729cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAdded != null) {
1730cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            N = mAdded.size();
1731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (N > 0) {
1732cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                added = new int[N];
1733cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                for (int i=0; i<N; i++) {
1734cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    added[i] = mAdded.get(i).mIndex;
17351b913519b1c03b084779851e81db2e1a11eb0b0dDianne Hackborn                    if (added[i] < 0) {
173613fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                        throwException(new IllegalStateException(
173713fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                "Failure saving state: active " + mAdded.get(i)
173813fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                                + " has cleared index: " + added[i]));
17391b913519b1c03b084779851e81db2e1a11eb0b0dDianne Hackborn                    }
1740cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (DEBUG) Log.v(TAG, "saveAllState: adding fragment #" + i
1741cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            + ": " + mAdded.get(i));
1742cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1743cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1744cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1745cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1746cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Now save back stack.
1747cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mBackStack != null) {
1748cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            N = mBackStack.size();
1749cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (N > 0) {
1750cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                backStack = new BackStackState[N];
1751cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                for (int i=0; i<N; i++) {
1752cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    backStack[i] = new BackStackState(this, mBackStack.get(i));
1753cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    if (DEBUG) Log.v(TAG, "saveAllState: adding back stack #" + i
1754cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            + ": " + mBackStack.get(i));
1755cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1756cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1757cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1758cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1759cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        FragmentManagerState fms = new FragmentManagerState();
1760cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        fms.mActive = active;
1761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        fms.mAdded = added;
1762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        fms.mBackStack = backStack;
1763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return fms;
1764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void restoreAllState(Parcelable state, ArrayList<Fragment> nonConfig) {
1767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // If there is no saved state at all, then there can not be
1768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // any nonConfig fragments either, so that is that.
1769cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (state == null) return;
1770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        FragmentManagerState fms = (FragmentManagerState)state;
1771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (fms.mActive == null) return;
1772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // First re-attach any non-config instances we are retaining back
1774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // to their saved state, so we don't try to instantiate them again.
1775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (nonConfig != null) {
1776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<nonConfig.size(); i++) {
1777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = nonConfig.get(i);
1778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (DEBUG) Log.v(TAG, "restoreAllState: re-attaching retained " + f);
1779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                FragmentState fs = fms.mActive[f.mIndex];
1780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                fs.mInstance = f;
1781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mSavedViewState = null;
1782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mBackStackNesting = 0;
1783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mInLayout = false;
1784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mAdded = false;
17852c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                f.mTarget = null;
1786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (fs.mSavedFragmentState != null) {
1787cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    fs.mSavedFragmentState.setClassLoader(mActivity.getClassLoader());
1788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    f.mSavedViewState = fs.mSavedFragmentState.getSparseParcelableArray(
1789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                            FragmentManagerImpl.VIEW_STATE_TAG);
1790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Build the full list of active fragments, instantiating them from
1795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // their saved state.
1796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActive = new ArrayList<Fragment>(fms.mActive.length);
1797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAvailIndices != null) {
1798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mAvailIndices.clear();
1799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        for (int i=0; i<fms.mActive.length; i++) {
1801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            FragmentState fs = fms.mActive[i];
1802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (fs != null) {
18030adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                Fragment f = fs.instantiate(mActivity, mParent);
18043a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                if (DEBUG) Log.v(TAG, "restoreAllState: active #" + i + ": " + f);
1805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mActive.add(f);
1806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // Now that the fragment is instantiated (or came from being
1807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // retained above), clear mInstance in case we end up re-restoring
1808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // from this FragmentState again.
1809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                fs.mInstance = null;
1810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            } else {
1811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mActive.add(null);
1812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (mAvailIndices == null) {
1813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mAvailIndices = new ArrayList<Integer>();
1814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
18153a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                if (DEBUG) Log.v(TAG, "restoreAllState: avail #" + i);
1816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mAvailIndices.add(i);
1817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Update the target of all retained fragments.
1821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (nonConfig != null) {
1822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<nonConfig.size(); i++) {
1823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = nonConfig.get(i);
18242c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                if (f.mTargetIndex >= 0) {
18252c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                    if (f.mTargetIndex < mActive.size()) {
18262c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                        f.mTarget = mActive.get(f.mTargetIndex);
1827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    } else {
1828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        Log.w(TAG, "Re-attaching retained fragment " + f
18292c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn                                + " target no longer exists: " + f.mTargetIndex);
1830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        f.mTarget = null;
1831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1832cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1833cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1834cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1835cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1836cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Build the list of currently added fragments.
1837cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (fms.mAdded != null) {
1838cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mAdded = new ArrayList<Fragment>(fms.mAdded.length);
1839cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<fms.mAdded.length; i++) {
1840cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mActive.get(fms.mAdded[i]);
1841cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f == null) {
184213fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                    throwException(new IllegalStateException(
184313fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn                            "No instantiated fragment for index #" + fms.mAdded[i]));
1844cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1845cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mAdded = true;
18463a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                if (DEBUG) Log.v(TAG, "restoreAllState: added #" + i + ": " + f);
18473a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                if (mAdded.contains(f)) {
18483a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                    throw new IllegalStateException("Already added!");
18493a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                }
1850cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mAdded.add(f);
1851cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1852cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } else {
1853cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mAdded = null;
1854cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1855cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1856cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        // Build the back stack.
1857cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (fms.mBackStack != null) {
1858cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mBackStack = new ArrayList<BackStackRecord>(fms.mBackStack.length);
1859cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<fms.mBackStack.length; i++) {
1860cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                BackStackRecord bse = fms.mBackStack[i].instantiate(this);
18613a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                if (DEBUG) {
18623a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                    Log.v(TAG, "restoreAllState: back stack #" + i
1863cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        + " (index " + bse.mIndex + "): " + bse);
18643a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                    LogWriter logw = new LogWriter(TAG);
18653a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                    PrintWriter pw = new PrintWriter(logw);
18663a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                    bse.dump("  ", pw, false);
18673a7571011a8f2c2e2685c4e3e7a6fa46673ee7eaDianne Hackborn                }
1868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mBackStack.add(bse);
1869cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (bse.mIndex >= 0) {
1870cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    setBackStackIndex(bse.mIndex, bse);
1871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } else {
1874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mBackStack = null;
1875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
18780adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    public void attachActivity(FragmentActivity activity,
18790adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn            FragmentContainer container, Fragment parent) {
188013fb2b96fa8464e7b8514c57e1ad5ea782b3a52cDianne Hackborn        if (mActivity != null) throw new IllegalStateException("Already attached");
1881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActivity = activity;
18820adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mContainer = container;
18830adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mParent = parent;
1884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void noteStateNotSaved() {
1887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mStateSaved = false;
1888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchCreate() {
1891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mStateSaved = false;
1892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        moveToState(Fragment.CREATED, false);
1893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchActivityCreated() {
1896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mStateSaved = false;
1897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        moveToState(Fragment.ACTIVITY_CREATED, false);
1898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchStart() {
1901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mStateSaved = false;
1902cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        moveToState(Fragment.STARTED, false);
1903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1904cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchResume() {
1906cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mStateSaved = false;
1907cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        moveToState(Fragment.RESUMED, false);
1908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1909cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchPause() {
1911cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        moveToState(Fragment.STARTED, false);
1912cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1913cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1914cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchStop() {
1915681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn        // See saveAllState() for the explanation of this.  We do this for
1916681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn        // all platform versions, to keep our behavior more consistent between
1917681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn        // them.
1918681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn        mStateSaved = true;
1919681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn
1920e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        moveToState(Fragment.STOPPED, false);
1921cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1922cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1923218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn    public void dispatchReallyStop() {
1924218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn        moveToState(Fragment.ACTIVITY_CREATED, false);
1925681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn    }
1926681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn
19270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    public void dispatchDestroyView() {
19280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        moveToState(Fragment.CREATED, false);
19290adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn    }
19300adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn
1931cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchDestroy() {
1932cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mDestroyed = true;
1933e8b402b00c0cbdac050c349a5fc89c34580f3185Dianne Hackborn        execPendingActions();
1934cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        moveToState(Fragment.INITIALIZING, false);
1935cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActivity = null;
19360adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mContainer = null;
19370adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn        mParent = null;
1938cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1939cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1940cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchConfigurationChanged(Configuration newConfig) {
1941464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
1942cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mAdded.size(); i++) {
1943cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
1944cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null) {
19450adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    f.performConfigurationChanged(newConfig);
1946cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1947cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1948cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1949cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1950cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1951cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchLowMemory() {
1952464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
1953cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mAdded.size(); i++) {
1954cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
1955cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (f != null) {
19560adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    f.performLowMemory();
1957cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1958cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1959cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1960cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1961cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1962cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean dispatchCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1963cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        boolean show = false;
1964cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        ArrayList<Fragment> newMenus = null;
1965464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
1966cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mAdded.size(); i++) {
1967cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
19680adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (f != null) {
19690adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    if (f.performCreateOptionsMenu(menu, inflater)) {
19700adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        show = true;
19710adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        if (newMenus == null) {
19720adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                            newMenus = new ArrayList<Fragment>();
19730adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        }
19740adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        newMenus.add(f);
1975cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
1976cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1977cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1979c1e87ac17c772ee3c5fd3b3f08321226e2c7ffa4Chris Banes
1980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mCreatedMenus != null) {
1981cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mCreatedMenus.size(); i++) {
1982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mCreatedMenus.get(i);
1983cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                if (newMenus == null || !newMenus.contains(f)) {
1984cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    f.onDestroyOptionsMenu();
1985cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1987cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1988c1e87ac17c772ee3c5fd3b3f08321226e2c7ffa4Chris Banes
1989cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCreatedMenus = newMenus;
1990c1e87ac17c772ee3c5fd3b3f08321226e2c7ffa4Chris Banes
1991cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return show;
1992cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1993cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1994cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean dispatchPrepareOptionsMenu(Menu menu) {
1995cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        boolean show = false;
1996464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
1997cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mAdded.size(); i++) {
1998cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
19990adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (f != null) {
20000adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    if (f.performPrepareOptionsMenu(menu)) {
20010adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                        show = true;
20020adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    }
2003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
2004cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
2005cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2006cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return show;
2007cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2008cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
2009cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean dispatchOptionsItemSelected(MenuItem item) {
2010464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
2011cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mAdded.size(); i++) {
2012cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
20130adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (f != null) {
20140adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    if (f.performOptionsItemSelected(item)) {
2015cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        return true;
2016cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
2017cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
2018cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
2019cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2020cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
2021cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2022cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
2023cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean dispatchContextItemSelected(MenuItem item) {
2024464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
2025cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mAdded.size(); i++) {
2026cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
20270adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (f != null) {
20280adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    if (f.performContextItemSelected(item)) {
2029cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                        return true;
2030cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    }
2031cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
2032cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
2033cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2034cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
2035cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2036cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
2037cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dispatchOptionsMenuClosed(Menu menu) {
2038464b6f3c93dda03359ec2d37c8205065922f2994Dianne Hackborn        if (mAdded != null) {
2039cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            for (int i=0; i<mAdded.size(); i++) {
2040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                Fragment f = mAdded.get(i);
20410adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                if (f != null) {
20420adacc1aa313d757ae1c517152cef838e0f35c13Dianne Hackborn                    f.performOptionsMenuClosed(menu);
2043cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
2044cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
2045cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2046cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2047461b48b4588ac21b97aa40553f04222c2c0344e7Chris Banes
2048cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static int reverseTransit(int transit) {
2049cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        int rev = 0;
2050cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        switch (transit) {
2051cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            case FragmentTransaction.TRANSIT_FRAGMENT_OPEN:
2052cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                rev = FragmentTransaction.TRANSIT_FRAGMENT_CLOSE;
2053cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                break;
2054cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE:
2055cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                rev = FragmentTransaction.TRANSIT_FRAGMENT_OPEN;
2056cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                break;
2057cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            case FragmentTransaction.TRANSIT_FRAGMENT_FADE:
2058cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                rev = FragmentTransaction.TRANSIT_FRAGMENT_FADE;
2059cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                break;
2060cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2061cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return rev;
2062cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
2063cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2064cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
20659277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public static final int ANIM_STYLE_OPEN_ENTER = 1;
20669277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public static final int ANIM_STYLE_OPEN_EXIT = 2;
20679277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public static final int ANIM_STYLE_CLOSE_ENTER = 3;
20689277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public static final int ANIM_STYLE_CLOSE_EXIT = 4;
20699277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public static final int ANIM_STYLE_FADE_ENTER = 5;
20709277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public static final int ANIM_STYLE_FADE_EXIT = 6;
20719277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn
2072cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static int transitToStyleIndex(int transit, boolean enter) {
2073cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        int animAttr = -1;
2074cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        switch (transit) {
2075cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            case FragmentTransaction.TRANSIT_FRAGMENT_OPEN:
20769277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                animAttr = enter ? ANIM_STYLE_OPEN_ENTER : ANIM_STYLE_OPEN_EXIT;
2077cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                break;
2078cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            case FragmentTransaction.TRANSIT_FRAGMENT_CLOSE:
20799277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                animAttr = enter ? ANIM_STYLE_CLOSE_ENTER : ANIM_STYLE_CLOSE_EXIT;
2080cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                break;
2081cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            case FragmentTransaction.TRANSIT_FRAGMENT_FADE:
20829277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn                animAttr = enter ? ANIM_STYLE_FADE_ENTER : ANIM_STYLE_FADE_EXIT;
2083cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                break;
2084cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
2085cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return animAttr;
2086cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
2087cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
2088