Fragment.java revision 79398eaefea45e61d839cf4e0534f0eafee70a09
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
19cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.app.Activity;
20cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.ComponentCallbacks;
21cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Context;
22cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.Intent;
23cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Configuration;
24cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.content.res.Resources;
25cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Bundle;
26cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcel;
27cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.os.Parcelable;
28cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.support.v4.util.DebugUtils;
29cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.AttributeSet;
30cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.util.SparseArray;
31cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu;
32cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.LayoutInflater;
33cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.Menu;
34cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuInflater;
35cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.MenuItem;
36cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View;
37cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ViewGroup;
38cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.ContextMenu.ContextMenuInfo;
39cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.View.OnCreateContextMenuListener;
40cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.view.animation.Animation;
41cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport android.widget.AdapterView;
42cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
43cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.FileDescriptor;
44cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.io.PrintWriter;
45cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornimport java.util.HashMap;
46cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
47cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornfinal class FragmentState implements Parcelable {
48cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final String mClassName;
49cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mIndex;
50cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final boolean mFromLayout;
51cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mFragmentId;
52cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final int mContainerId;
53cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final String mTag;
54cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final boolean mRetainInstance;
55e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final boolean mDetached;
56cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final Bundle mArguments;
57cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
58cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mSavedFragmentState;
59cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
60cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Fragment mInstance;
61cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
62cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentState(Fragment frag) {
63cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mClassName = frag.getClass().getName();
64cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = frag.mIndex;
65cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFromLayout = frag.mFromLayout;
66cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFragmentId = frag.mFragmentId;
67cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mContainerId = frag.mContainerId;
68cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTag = frag.mTag;
69cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = frag.mRetainInstance;
70e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mDetached = frag.mDetached;
71cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = frag.mArguments;
72cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
73cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
74cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public FragmentState(Parcel in) {
75cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mClassName = in.readString();
76cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = in.readInt();
77cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFromLayout = in.readInt() != 0;
78cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mFragmentId = in.readInt();
79cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mContainerId = in.readInt();
80cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTag = in.readString();
81cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = in.readInt() != 0;
82e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mDetached = in.readInt() != 0;
83cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = in.readBundle();
84cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mSavedFragmentState = in.readBundle();
85cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
86cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
87cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment instantiate(FragmentActivity activity) {
88cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mInstance != null) {
89cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return mInstance;
90cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
91cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
92cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mArguments != null) {
93cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mArguments.setClassLoader(activity.getClassLoader());
94cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
95cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
96cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance = Fragment.instantiate(activity, mClassName, mArguments);
97cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
98cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedFragmentState != null) {
99cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mSavedFragmentState.setClassLoader(activity.getClassLoader());
100cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mInstance.mSavedFragmentState = mSavedFragmentState;
101cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
102cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.setIndex(mIndex);
103cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mFromLayout = mFromLayout;
104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mRestored = true;
105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mFragmentId = mFragmentId;
106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mContainerId = mContainerId;
107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mTag = mTag;
108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mRetainInstance = mRetainInstance;
109e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        mInstance.mDetached = mDetached;
110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mInstance.mFragmentManager = activity.mFragments;
111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mInstance;
113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public int describeContents() {
116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return 0;
117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void writeToParcel(Parcel dest, int flags) {
120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeString(mClassName);
121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mIndex);
122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mFromLayout ? 1 : 0);
123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mFragmentId);
124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mContainerId);
125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeString(mTag);
126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeInt(mRetainInstance ? 1 : 0);
127e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        dest.writeInt(mDetached ? 1 : 0);
128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeBundle(mArguments);
129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        dest.writeBundle(mSavedFragmentState);
130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static final Parcelable.Creator<FragmentState> CREATOR
133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            = new Parcelable.Creator<FragmentState>() {
134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentState createFromParcel(Parcel in) {
135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentState(in);
136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public FragmentState[] newArray(int size) {
139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return new FragmentState[size];
140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    };
142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn/**
145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Static library support version of the framework's {@link android.app.Fragment}.
146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * Used to write apps that run on platforms prior to Android 3.0.  When running
147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * on Android 3.0 or above, this implementation is still used; it does not try
148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * to switch to the framework's implementation.  See the framework SDK
149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn * documentation for a class overview.
150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn */
151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackbornpublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener {
152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    private static final HashMap<String, Class<?>> sClassMap =
153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            new HashMap<String, Class<?>>();
154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int INITIALIZING = 0;     // Not yet created.
156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int CREATED = 1;          // Created.
157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static final int ACTIVITY_CREATED = 2; // The activity has finished its creation.
158e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STOPPED = 3;          // Fully created, not started.
159e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int STARTED = 4;          // Created and started, not resumed.
160e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    static final int RESUMED = 5;          // Created started and resumed.
161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mState = INITIALIZING;
163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Non-null if the fragment's view hierarchy is currently animating away,
165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // meaning we need to wait a bit on completely destroying it.  This is the
166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // view that is animating.
167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mAnimatingAway;
168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If mAnimatingAway != null, this is the state we should move to once the
170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // animation is done.
171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mStateAfterAnimating;
172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When instantiated from saved state, this is the saved state.
174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mSavedFragmentState;
175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    SparseArray<Parcelable> mSavedViewState;
176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Index into active fragment array.
178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mIndex = -1;
179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Internal unique name for this fragment;
181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mWho;
182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Construction arguments;
184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Bundle mArguments;
185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target fragment.
187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    Fragment mTarget;
188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1892c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    // For use when retaining a fragment: this is the index of the last mTarget.
1902c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn    int mTargetIndex = -1;
1912c4b5dbfee5232bcbbcb74b84ce9147b62a9d789Dianne Hackborn
192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Target request code.
193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mTargetRequestCode;
194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if the fragment is in the list of added fragments.
196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mAdded;
197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being removed from its activity.
199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRemoving;
200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if the fragment is in the resumed state.
202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mResumed;
203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true if this fragment was instantiated from a layout file.
205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mFromLayout;
206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the view has actually been inflated in its layout.
208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mInLayout;
209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // True if this fragment has been restored from previously saved state.
211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRestored;
212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Number of active back stack entries this fragment is in.
214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mBackStackNesting;
215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The fragment manager we are associated with.  Set as soon as the
217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragment is used in a transaction; cleared after it has been removed
218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from all transactions.
219abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    FragmentManagerImpl mFragmentManager;
220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Activity this fragment is attached to.
222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    FragmentActivity mActivity;
223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional identifier for this fragment -- either the container ID if it
225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // was dynamically added to the view hierarchy, or the ID supplied in
226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // layout.
227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mFragmentId;
228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // When a fragment is being dynamically added to the view hierarchy, this
230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // is the identifier of the parent container it is being added to.
231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mContainerId;
232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The optional named tag for this fragment -- usually used to find
234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // fragments that are not part of the layout.
235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    String mTag;
236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Set to true when the app has requested that this fragment be hidden
238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // from the user.
239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHidden;
240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
241e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    // Set to true when the app has requested that this fragment be deactivated.
242e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    boolean mDetached;
243e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment would like its instance retained across
245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // configuration changes.
246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetainInstance;
247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment is being retained across the current config change.
249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mRetaining;
250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If set this fragment has menu items to contribute.
252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mHasMenu;
2532a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
2542a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    // Set to true to allow the fragment's menu to be shown.
2552a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    boolean mMenuVisible = true;
2562a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // Used to verify that subclasses call through to super class.
258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mCalled;
259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // If app has requested a specific animation, this is the one to use.
261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    int mNextAnim;
262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The parent container of the fragment after dynamically added to UI.
264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    ViewGroup mContainer;
265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The View generated for this fragment.
267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mView;
268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    // The real inner view that will save/restore state.
270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    View mInnerView;
271abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
272abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // Whether this fragment should defer starting until after other fragments
273abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    // have been started and their loaders are finished.
274abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    boolean mDeferStart;
27579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell
27679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    // Hint provided by the app that this fragment is currently visible to the user.
27779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    boolean mUserVisibleHint = true;
278abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
279cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    LoaderManagerImpl mLoaderManager;
280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mLoadersStarted;
281cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    boolean mCheckedForLoaderManager;
282cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
283cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
2845c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * State information that has been retrieved from a fragment instance
2855c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * through {@link FragmentManager#saveFragmentInstanceState(Fragment)
2865c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
2875c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
2885c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public static class SavedState implements Parcelable {
2895c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        final Bundle mState;
2905c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
2915c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Bundle state) {
2925c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = state;
2935c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
2945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
2955c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        SavedState(Parcel in, ClassLoader loader) {
2965c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            mState = in.readBundle();
2975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            if (loader != null && mState != null) {
2985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                mState.setClassLoader(loader);
2995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
3035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public int describeContents() {
3045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            return 0;
3055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        @Override
3085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public void writeToParcel(Parcel dest, int flags) {
3095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            dest.writeBundle(mState);
3105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
3115c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3125c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        public static final Parcelable.Creator<SavedState> CREATOR
3135c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                = new Parcelable.Creator<SavedState>() {
3145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState createFromParcel(Parcel in) {
3155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState(in, null);
3165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            public SavedState[] newArray(int size) {
3195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                return new SavedState[size];
3205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            }
3215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        };
3225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
3235c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
3245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when
326cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * there is an instantiation failure.
327cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    static public class InstantiationException extends RuntimeException {
329cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        public InstantiationException(String msg, Exception cause) {
330cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            super(msg, cause);
331cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
332cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
333cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
334cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
335cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Default constructor.  <strong>Every</strong> fragment must have an
336cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * empty constructor, so it can be instantiated when restoring its
337cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity's state.  It is strongly recommended that subclasses do not
338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * have other constructors with parameters, since these constructors
339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will not be called when the fragment is re-instantiated; instead,
340cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * arguments can be supplied by the caller with {@link #setArguments}
341cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and later retrieved by the Fragment with {@link #getArguments}.
342cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Applications should generally not implement a constructor.  The
344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * first place application code an run where the fragment is ready to
345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be used is in {@link #onAttach(Activity)}, the point where the fragment
346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is actually associated with its activity.  Some applications may also
347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * want to implement {@link #onInflate} to retrieve attributes from a
348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * layout resource, though should take care here because this happens for
349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the fragment is attached to its activity.
350cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public Fragment() {
352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Like {@link #instantiate(Context, String, Bundle)} but with a null
356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * argument Bundle.
357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
358cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static Fragment instantiate(Context context, String fname) {
359cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return instantiate(context, fname, null);
360cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
361cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
362cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
363cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Create a new instance of a Fragment with the given class name.  This is
364cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the same as calling its empty constructor.
365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
366cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param context The calling context being used to instantiate the fragment.
367cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is currently just used to get its ClassLoader.
368cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fname The class name of the fragment to instantiate.
369cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args Bundle of arguments to supply to the fragment, which it
370cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can retrieve with {@link #getArguments()}.  May be null.
371cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Returns a new fragment instance.
372cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @throws InstantiationException If there is a failure in instantiating
373cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the given fragment class.  This is a runtime exception; it is not
374cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * normally expected to happen.
375cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
376cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public static Fragment instantiate(Context context, String fname, Bundle args) {
377cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        try {
378cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Class<?> clazz = sClassMap.get(fname);
379cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (clazz == null) {
380cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                // Class not found in the cache, see if it's real, and try to add it
381cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                clazz = context.getClassLoader().loadClass(fname);
382cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                sClassMap.put(fname, clazz);
383cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
384cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Fragment f = (Fragment)clazz.newInstance();
385cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (args != null) {
386cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                args.setClassLoader(f.getClass().getClassLoader());
387cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                f.mArguments = args;
388cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
389cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return f;
390cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (ClassNotFoundException e) {
391cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
392cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
393cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
394cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (java.lang.InstantiationException e) {
395cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
396cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
397cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
398cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        } catch (IllegalAccessException e) {
399cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new InstantiationException("Unable to instantiate fragment " + fname
400cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + ": make sure class name exists, is public, and has an"
401cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    + " empty constructor that is public", e);
402cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
403cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
404cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
405e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final void restoreViewState() {
406cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
407cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mInnerView.restoreHierarchyState(mSavedViewState);
408cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mSavedViewState = null;
409cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
410cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
411cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
412e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final void setIndex(int index) {
413cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mIndex = index;
414cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mWho = "android:fragment:" + mIndex;
415e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
416cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
417e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    final boolean isInBackStack() {
418e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn        return mBackStackNesting > 0;
419e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
420e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
421cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
422cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override equals().
423cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
424cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public boolean equals(Object o) {
425cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.equals(o);
426cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
427cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
428cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
429cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Subclasses can not override hashCode().
430cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
431cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override final public int hashCode() {
432cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return super.hashCode();
433cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
434cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
435cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    @Override
436cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public String toString() {
437cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        StringBuilder sb = new StringBuilder(128);
438cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        DebugUtils.buildShortClassTag(this, sb);
439cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mIndex >= 0) {
440cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" #");
441cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mIndex);
442cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
443cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentId != 0) {
444cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" id=0x");
445cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(Integer.toHexString(mFragmentId));
446cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
447cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTag != null) {
448cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(" ");
449cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            sb.append(mTag);
450cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
451cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        sb.append('}');
452cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return sb.toString();
453cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
454cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
455cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
456cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the identifier this fragment is known by.  This is either
457cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the android:id value supplied in a layout or the container view ID
458cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * supplied when adding the fragment.
459cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
460cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getId() {
461cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentId;
462cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
463cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
464cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
465cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the tag name of the fragment, if specified.
466cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
467cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public String getTag() {
468cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTag;
469cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
470cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
471cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
472cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Supply the construction arguments for this fragment.  This can only
473cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be called before the fragment has been attached to its activity; that
474cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is, you should call it immediately after constructing the fragment.  The
475cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * arguments supplied here will be retained across fragment destroy and
476cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * creation.
477cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
478cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setArguments(Bundle args) {
479cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mIndex >= 0) {
480cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment already active");
481cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
482cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mArguments = args;
483cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
484cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
485cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
486cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the arguments supplied when the fragment was instantiated,
487cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if any.
488cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
489cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Bundle getArguments() {
490cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mArguments;
491cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
492cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
493cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
4945c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * Set the initial saved state that this Fragment should restore itself
4955c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * from when first being constructed, as returned by
4965c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * {@link FragmentManager#saveFragmentInstanceState(Fragment)
4975c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * FragmentManager.saveFragmentInstanceState}.
4985c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     *
4995c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     * @param state The state the fragment should be restored from.
5005c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn     */
5015c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    public void setInitialSavedState(SavedState state) {
5025c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        if (mIndex >= 0) {
5035c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn            throw new IllegalStateException("Fragment already active");
5045c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        }
5055c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn        mSavedFragmentState = state != null && state.mState != null
5065c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn                ? state.mState : null;
5075c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    }
5085c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn
5095c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn    /**
510cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Optional target for this fragment.  This may be used, for example,
511cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if this fragment is being started by another, and when done wants to
512cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * give a result back to the first.  The target set here is retained
513cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * across instances via {@link FragmentManager#putFragment
514cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * FragmentManager.putFragment()}.
515cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
516cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fragment The fragment that is the target of this one.
517cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode Optional request code, for convenience if you
518cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are going to call back with {@link #onActivityResult(int, int, Intent)}.
519cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
520cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setTargetFragment(Fragment fragment, int requestCode) {
521cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTarget = fragment;
522cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mTargetRequestCode = requestCode;
523cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
524cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
525cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
526cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target fragment set by {@link #setTargetFragment}.
527cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
528cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Fragment getTargetFragment() {
529cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTarget;
530cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
531cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
532cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
533cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the target request code set by {@link #setTargetFragment}.
534cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
535cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public int getTargetRequestCode() {
536cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mTargetRequestCode;
537cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
538cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
539cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
540cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the Activity this fragment is currently associated with.
541cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
542cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentActivity getActivity() {
543cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity;
544cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
545cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
546cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
547cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return <code>getActivity().getResources()</code>.
548cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
549cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public Resources getResources() {
550cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
551cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
552cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
553cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity.getResources();
554cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
555cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
556cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
557cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized, styled CharSequence from the application's package's
558cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
559cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
560cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the CharSequence text
561cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
562cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public final CharSequence getText(int resId) {
563cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getText(resId);
564cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
565cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
566cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
567cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized string from the application's package's
568cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table.
569cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
570cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the string
571cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
572cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public final String getString(int resId) {
573cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId);
574cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
575cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
576cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
577cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return a localized formatted string from the application's package's
578cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default string table, substituting the format arguments as defined in
579cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link java.util.Formatter} and {@link java.lang.String#format}.
580cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
581cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resId Resource id for the format string
582cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param formatArgs The format arguments that will be used for substitution.
583cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
584cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
585cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public final String getString(int resId, Object... formatArgs) {
586cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return getResources().getString(resId, formatArgs);
587cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
588cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
589cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
590cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the FragmentManager for interacting with fragments associated
591cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * with this fragment's activity.  Note that this will be non-null slightly
592cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * before {@link #getActivity()}, during the time from when the fragment is
593cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * placed in a {@link FragmentTransaction} until it is committed and
594cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * attached to its activity.
595cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
596cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public FragmentManager getFragmentManager() {
597cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mFragmentManager;
598cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
599cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
600cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
601cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently added to its activity.
602cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
603cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isAdded() {
604cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity != null && mAdded;
605cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
606cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
607cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
6089c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Return true if the fragment has been explicitly detached from the UI.
6099c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * That is, {@link FragmentTransaction#detach(Fragment)
6109c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * FragmentTransaction.detach(Fragment)} has been used on it.
6119c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
6129c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    final public boolean isDetached() {
6139c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        return mDetached;
6149c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
6159c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
6169c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
617cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if this fragment is currently being removed from its
618cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * activity.  This is  <em>not</em> whether its activity is finishing, but
619cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * rather whether it is in the process of being removed from its activity.
620cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
621cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isRemoving() {
622cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRemoving;
623cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
624cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
625cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
626cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the layout is included as part of an activity view
627cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * hierarchy via the &lt;fragment&gt; tag.  This will always be true when
628cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragments are created through the &lt;fragment&gt; tag, <em>except</em>
629cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the case where an old fragment is restored from a previous state and
630cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * it does not appear in the layout of the current state.
631cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
632cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isInLayout() {
633cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mInLayout;
634cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
635cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
636cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
637cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is in the resumed state.  This is true
638cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for the duration of {@link #onResume()} and {@link #onPause()} as well.
639cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
640cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isResumed() {
641cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mResumed;
642cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
643cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
644cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
645cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment is currently visible to the user.  This means
646cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * it: (1) has been added, (2) has its view attached to the window, and
647cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * (3) is not hidden.
648cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
649cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isVisible() {
650cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return isAdded() && !isHidden() && mView != null
651cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE;
652cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
653cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
654cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
655cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return true if the fragment has been hidden.  By default fragments
656cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * are shown.  You can find out about changes to this state with
657cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onHiddenChanged}.  Note that the hidden state is orthogonal
658cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to other states -- that is, to be visible to the user, a fragment
659cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * must be both started and not hidden.
660cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
661cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean isHidden() {
662cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mHidden;
663cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
664cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
665cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
666cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the hidden state (as returned by {@link #isHidden()} of
667cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the fragment has changed.  Fragments start out not hidden; this will
668cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be called whenever the fragment changes state from that.
669cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param hidden True if the fragment is now hidden, false if it is not
670cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * visible.
671cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
672cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onHiddenChanged(boolean hidden) {
673cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
674cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
675cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
676cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Control whether a fragment instance is retained across Activity
677cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * re-creation (such as from a configuration change).  This can only
678cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * be used with fragments not in the back stack.  If set, the fragment
679cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * lifecycle will be slightly different when an activity is recreated:
680cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <ul>
681cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still
682cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * will be, because the fragment is being detached from its current activity).
683cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onCreate(Bundle)} will not be called since the fragment
684cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is not being re-created.
685cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b>
686cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still be called.
687cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * </ul>
688cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
689cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setRetainInstance(boolean retain) {
690cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mRetainInstance = retain;
691cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
692cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
693cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    final public boolean getRetainInstance() {
694cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mRetainInstance;
695cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
696cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
697cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
698cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Report that this fragment would like to participate in populating
699cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the options menu by receiving a call to {@link #onCreateOptionsMenu}
700cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and related methods.
701cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
702cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param hasMenu If true, the fragment has menu items to contribute.
703cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
704cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void setHasOptionsMenu(boolean hasMenu) {
705cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mHasMenu != hasMenu) {
706cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mHasMenu = hasMenu;
707cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (isAdded() && !isHidden()) {
708681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn                mActivity.supportInvalidateOptionsMenu();
709cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
710cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
711cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
7122a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
7132a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    /**
7142a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * Set a hint for whether this fragment's menu should be visible.  This
7152a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * is useful if you know that a fragment has been placed in your view
7162a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * hierarchy so that the user can not currently seen it, so any menu items
7172a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * it has should also not be shown.
7182a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     *
7192a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * @param menuVisible The default is true, meaning the fragment's menu will
7202a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     * be shown as usual.  If false, the user will not see the menu.
7212a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn     */
7222a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    public void setMenuVisibility(boolean menuVisible) {
7232a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        if (mMenuVisible != menuVisible) {
7242a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            mMenuVisible = menuVisible;
7252a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            if (mHasMenu && isAdded() && !isHidden()) {
7262a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                mActivity.supportInvalidateOptionsMenu();
7272a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn            }
7282a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        }
7292a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn    }
7302a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn
731cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
73279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * Set a hint to the system about whether this fragment's UI is currently visible
73379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * to the user. This hint defaults to true and is persistent across fragment instance
73479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * state save and restore.
735abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
73679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * <p>An app may set this to false to indicate that the fragment's UI is
73779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * scrolled out of visibility or is otherwise not directly visible to the user.
73879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * This may be used by the system to prioritize operations such as fragment lifecycle updates
73979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * or loader ordering behavior.</p>
740abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     *
74179398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @param isVisibleToUser true if this fragment's UI is currently visible to the user (default),
74279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     *                        false if it is not.
743abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
74479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public void setUserVisibleHint(boolean isVisibleToUser) {
74579398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        if (!mUserVisibleHint && isVisibleToUser && mState < STARTED) {
746abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell            mFragmentManager.performPendingDeferredStart(this);
747abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell        }
74879398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        mUserVisibleHint = isVisibleToUser;
74979398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        mDeferStart = !isVisibleToUser;
750abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
751abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
752abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
75379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @return The current value of the user-visible hint on this fragment.
75479398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell     * @see #setUserVisibleHint(boolean)
755abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell     */
75679398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell    public boolean getUserVisibleHint() {
75779398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell        return mUserVisibleHint;
758abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    }
759abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell
760abc968f1eba800c34a4008deb43b015da5d23a5fAdam Powell    /**
761cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Return the LoaderManager for this fragment, creating it if needed.
762cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
763cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public LoaderManager getLoaderManager() {
764cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
765cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            return mLoaderManager;
766cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
767cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
768cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
769cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
770cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCheckedForLoaderManager = true;
771cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, true);
772cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mLoaderManager;
773cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
774cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
775cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
776cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Call {@link Activity#startActivity(Intent)} on the fragment's
777cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
778cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
779cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivity(Intent intent) {
780cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
781cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
782cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
783cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActivity.startActivityFromFragment(this, intent, -1);
784cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
785cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
786cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
787cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's
788cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * containing Activity.
789cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
790cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void startActivityForResult(Intent intent, int requestCode) {
791cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity == null) {
792cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            throw new IllegalStateException("Fragment " + this + " not attached to Activity");
793cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
794cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mActivity.startActivityFromFragment(this, intent, requestCode);
795cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
796cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
797cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
798cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Receive the result from a previous call to
799cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #startActivityForResult(Intent, int)}.  This follows the
800cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * related Activity API as described there in
801cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onActivityResult(int, int, Intent)}.
802cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
803cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param requestCode The integer request code originally supplied to
804cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    startActivityForResult(), allowing you to identify who this
805cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                    result came from.
806cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param resultCode The integer result code returned by the child activity
807cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *                   through its setResult().
808cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param data An Intent, which can return result data to the caller
809cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *               (various data can be attached to Intent "extras").
810cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
811cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onActivityResult(int requestCode, int resultCode, Intent data) {
812cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
813cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
814cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
815cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @hide Hack so that DialogFragment can make its Dialog before creating
816cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its views, and the view construction can use the dialog's context for
817cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inflation.  Maybe this should become a public API. Note sure.
818cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
819cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public LayoutInflater getLayoutInflater(Bundle savedInstanceState) {
820cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mActivity.getLayoutInflater();
821cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
822cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
823cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
824cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is being created as part of a view layout
825cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * inflation, typically from setting the content view of an activity.  This
8269277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * may be called immediately after the fragment is created from a <fragment>
827cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tag in a layout file.  Note this is <em>before</em> the fragment's
828cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} has been called; all you should do here is
8299277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * parse the attributes and save them away.
830cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
831cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This is called every time the fragment is inflated, even if it is
8329277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * being inflated into a new instance with saved state.  It typically makes
8339277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * sense to re-parse the parameters each time, to allow them to change with
8349277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * different configurations.</p>
8359277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8369277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Here is a typical implementation of a fragment that can take parameters
8379277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * both through attributes supplied here as well from {@link #getArguments()}:</p>
8389277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8399277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
8409277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      fragment}
8419277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8429277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
8439277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * declaration for the styleable used here is:</p>
8449277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8459277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
846cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
8479277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>The fragment can then be declared within its activity's content layout
8489277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * through a tag like this:</p>
8499277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8509277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
8519277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8529277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * <p>This fragment can also be created dynamically from arguments given
8539277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * at runtime in the arguments Bundle; here is an example of doing so at
8549277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * creation of the containing activity:</p>
8559277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8569277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
8579277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *      create}
8589277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     *
8599277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn     * @param activity The Activity that is inflating this fragment.
860cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param attrs The attributes at the tag where the fragment is
861cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * being created.
862cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
863cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
864cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
8659277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
866cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
867cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
868cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
869cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
870cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment is first attached to its activity.
871cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} will be called after this.
872cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
873cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onAttach(Activity activity) {
874cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
875cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
876cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
877cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
878cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a fragment loads an animation.
879cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
8809277b9e4419c1f0b5236d9b573a7cc0b23d56402Dianne Hackborn    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
881cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
882cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
883cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
884cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
885cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to do initial creation of a fragment.  This is called after
886cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onAttach(Activity)} and before
887cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
888cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
889cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Note that this can be called while the fragment's activity is
890cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * still in the process of being created.  As such, you can not rely
891cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * on things like the activity's content view hierarchy being initialized
892cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at this point.  If you want to do work once the activity itself is
893cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, see {@link #onActivityCreated(Bundle)}.
894cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
895cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
896cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
897cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
898cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreate(Bundle savedInstanceState) {
899cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
900cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
901cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
902cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
903cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to have the fragment instantiate its user interface view.
904cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is optional, and non-graphical fragments can return null (which
905cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is the default implementation).  This will be called between
906cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
907cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
908cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>If you return a View from here, you will later be called in
909cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onDestroyView} when the view is being released.
910cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
911cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param inflater The LayoutInflater object that can be used to inflate
912cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * any views in the fragment,
913cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param container If non-null, this is the parent view that the fragment's
914cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * UI should be attached to.  The fragment should not add the view itself,
915cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * but this can be used to generate the LayoutParams of the view.
916cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
917cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * from a previous saved state as given here.
918cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
919cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return Return the View for the fragment's UI, or null.
920cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
921cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public View onCreateView(LayoutInflater inflater, ViewGroup container,
922cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            Bundle savedInstanceState) {
923cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return null;
924cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
925cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
926cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
927e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}
928e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * has returned, but before any saved state has been restored in to the view.
929e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * This gives subclasses a chance to initialize themselves once
930e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * they know their view hierarchy has been completely created.  The fragment's
931e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * view hierarchy is not however attached to its parent at this point.
932e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}.
933e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * @param savedInstanceState If non-null, this fragment is being re-constructed
934e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     * from a previous saved state as given here.
935e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn     */
936e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    public void onViewCreated(View view, Bundle savedInstanceState) {
937e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    }
938e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn
939e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn    /**
940cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}),
941cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * if provided.
942cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
943cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return The fragment's root view, or null if it has no layout.
944cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
945cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public View getView() {
946cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return mView;
947cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
948cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
949cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
950cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment's activity has been created and this
951cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * fragment's view hierarchy instantiated.  It can be used to do final
952cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * initialization once these pieces are in place, such as retrieving
953cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * views or restoring state.  It is also useful for fragments that use
954cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #setRetainInstance(boolean)} to retain their instance,
955cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as this callback tells the fragment when it is fully associated with
956cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the new activity instance.  This is called after {@link #onCreateView}
957cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * and before {@link #onStart()}.
958cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
959cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param savedInstanceState If the fragment is being re-created from
960cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * a previous saved state, this is the state.
961cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
962cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onActivityCreated(Bundle savedInstanceState) {
963cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
964cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
965cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
966cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
967cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is visible to the user.  This is generally
968cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStart() Activity.onStart} of the containing
969cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
970cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
971cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStart() {
972cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
973cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
974cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!mLoadersStarted) {
975cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoadersStarted = true;
976cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (!mCheckedForLoaderManager) {
977cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mCheckedForLoaderManager = true;
978cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false);
979cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
980cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mLoaderManager != null) {
981cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mLoaderManager.doStart();
982cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
983cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
984cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
985cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
986cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
987cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is visible to the user and actively running.
988cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This is generally
989cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onResume() Activity.onResume} of the containing
990cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
991cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
992cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onResume() {
993cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
994cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
995cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
996cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
997cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called to ask the fragment to save its current dynamic state, so it
998cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can later be reconstructed in a new instance of its process is
999cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * restarted.  If a new instance of the fragment later needs to be
1000cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * created, the data you place in the Bundle here will be available
1001cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * in the Bundle given to {@link #onCreate(Bundle)},
1002cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and
1003cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onActivityCreated(Bundle)}.
1004cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1005cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle)
1006cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity.onSaveInstanceState(Bundle)} and most of the discussion there
1007cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * applies here as well.  Note however: <em>this method may be called
1008cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * at any time before {@link #onDestroy()}</em>.  There are many situations
1009cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * where a fragment may be mostly torn down (such as when placed on the
1010cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * back stack with no UI showing), but its state will not be saved until
1011cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its owning activity actually needs to save its state.
1012cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1013cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param outState Bundle in which to place your saved state.
1014cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1015cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onSaveInstanceState(Bundle outState) {
1016cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1017cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1018cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onConfigurationChanged(Configuration newConfig) {
1019cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1020cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1021cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1022cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1023cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer resumed.  This is generally
1024cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onPause() Activity.onPause} of the containing
1025cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1026cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1027cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPause() {
1028cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1029cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1030cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1031cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1032cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the Fragment is no longer started.  This is generally
1033cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * tied to {@link Activity#onStop() Activity.onStop} of the containing
1034cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Activity's lifecycle.
1035cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1036cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onStop() {
1037cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1038cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1039cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1040cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onLowMemory() {
1041cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1042cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1043cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1044cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1045cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the view previously created by {@link #onCreateView} has
1046cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been detached from the fragment.  The next time the fragment needs
1047cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be displayed, a new view will be created.  This is called
1048cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDestroy()}.  It is called
1049cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <em>regardless</em> of whether {@link #onCreateView} returned a
1050cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * non-null view.  Internally it is called after the view's state has
1051cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * been saved but before it has been removed from its parent.
1052cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1053cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyView() {
1054cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1055cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1056cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1057cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1058cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer in use.  This is called
1059cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * after {@link #onStop()} and before {@link #onDetach()}.
1060cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1061cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroy() {
1062cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1063cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager
1064cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        //        + " mLoaderManager=" + mLoaderManager);
1065cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (!mCheckedForLoaderManager) {
1066cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mCheckedForLoaderManager = true;
1067cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false);
1068cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1069cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
1070cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoaderManager.doDestroy();
1071cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1072cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1073cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1074cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
10759c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * Called by the fragment manager once this fragment has been removed,
10769c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * so that we don't have any left-over state if the application decides
10779c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * to re-use the instance.  This only clears state that the framework
10789c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     * internally manages, not things the application sets.
10799c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn     */
10809c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void initState() {
10819c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mIndex = -1;
10829c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mWho = null;
10839c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mAdded = false;
10849c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRemoving = false;
10859c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mResumed = false;
10869c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFromLayout = false;
10879c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mInLayout = false;
10889c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRestored = false;
10899c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mBackStackNesting = 0;
10909c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentManager = null;
10912a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        mActivity = null;
10929c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mFragmentId = 0;
10939c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mContainerId = 0;
10949c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mTag = null;
10959c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mHidden = false;
10969c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mDetached = false;
10979c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mRetaining = false;
10989c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mLoaderManager = null;
10999c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mLoadersStarted = false;
11009c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        mCheckedForLoaderManager = false;
11019c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
11029c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
11039c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    /**
1104cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when the fragment is no longer attached to its activity.  This
1105cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * is called after {@link #onDestroy()}.
1106cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1107cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDetach() {
1108cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        mCalled = true;
1109cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1110cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1111cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1112cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Initialize the contents of the Activity's standard options menu.  You
1113cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * should place your menu items in to <var>menu</var>.  For this method
1114cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * to be called, you must have first called {@link #setHasOptionsMenu}.  See
1115cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu}
1116cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
1117cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1118cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu in which you place your items.
1119cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1120cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1121cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onPrepareOptionsMenu
1122cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onOptionsItemSelected
1123cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1124cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
1125cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1126cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1127cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1128cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Prepare the Screen's standard options menu to be displayed.  This is
1129cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called right before the menu is shown, every time it is shown.  You can
1130cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * use this method to efficiently enable/disable items or otherwise
1131cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * dynamically modify the contents.  See
1132cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu}
1133cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for more information.
1134cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1135cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1136cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
1137cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1138cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #setHasOptionsMenu
1139cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1140cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1141cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onPrepareOptionsMenu(Menu menu) {
1142cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1143cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1144cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1145cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when this fragment's option menu items are no longer being
1146cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the overall options menu.  Receiving this call means that
1147cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu needed to be rebuilt, but this fragment's items were not
1148cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)}
1149cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * was not called).
1150cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1151cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onDestroyOptionsMenu() {
1152cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1153cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1154cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1155cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in your options menu is selected.
1156cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation simply returns false to have the normal
1157cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * processing happen (calling the item's Runnable or sending a message to
1158cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * its Handler as appropriate).  You can use this method for any items
1159cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * for which you would like to do processing without those other
1160cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * facilities.
1161cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1162cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>Derived classes should call through to the base class for it to
1163cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * perform the default menu handling.
1164cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1165cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The menu item that was selected.
1166cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1167cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal menu processing to
1168cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
1169cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1170cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #onCreateOptionsMenu
1171cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1172cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onOptionsItemSelected(MenuItem item) {
1173cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1174cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1175cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1176cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1177cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever the options menu is being closed (either by the user canceling
1178cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the menu with the back/menu button, or when an item is selected).
1179cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1180cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param menu The options menu as last shown or first initialized by
1181cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *             onCreateOptionsMenu().
1182cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1183cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onOptionsMenuClosed(Menu menu) {
1184cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1185cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1186cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1187cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Called when a context menu for the {@code view} is about to be shown.
1188cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Unlike {@link #onCreateOptionsMenu}, this will be called every
1189cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * time the context menu is about to be shown and should be populated for
1190cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the view (or item inside the view for {@link AdapterView} subclasses,
1191cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * this can be found in the {@code menuInfo})).
1192cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1193cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an
1194cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * item has been selected.
1195cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1196cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * The default implementation calls up to
1197cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though
1198cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * you can not call this implementation if you don't want that behavior.
1199cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1200cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * It is not safe to hold onto the context menu after this method returns.
1201cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@inheritDoc}
1202cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1203cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
1204cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        getActivity().onCreateContextMenu(menu, v, menuInfo);
1205cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1206cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1207cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1208cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Registers a context menu to be shown for the given view (multiple views
1209cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * can show the context menu). This method will set the
1210cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link OnCreateContextMenuListener} on the view to this fragment, so
1211cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be
1212cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * called when it is time to show the context menu.
1213cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1214cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #unregisterForContextMenu(View)
1215cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should show a context menu.
1216cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1217cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void registerForContextMenu(View view) {
1218cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(this);
1219cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1220cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1221cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1222cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Prevents a context menu to be shown for the given view. This method will
1223cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * remove the {@link OnCreateContextMenuListener} on the view.
1224cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1225cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @see #registerForContextMenu(View)
1226cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param view The view that should stop showing a context menu.
1227cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1228cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void unregisterForContextMenu(View view) {
1229cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        view.setOnCreateContextMenuListener(null);
1230cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1231cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1232cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1233cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * This hook is called whenever an item in a context menu is selected. The
1234cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * default implementation simply returns false to have the normal processing
1235cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * happen (calling the item's Runnable or sending a message to its Handler
1236cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * as appropriate). You can use this method for any items for which you
1237cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * would like to do processing without those other facilities.
1238cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1239cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Use {@link MenuItem#getMenuInfo()} to get extra information set by the
1240cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * View that added this menu item.
1241cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * <p>
1242cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Derived classes should call through to the base class for it to perform
1243cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * the default menu handling.
1244cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1245cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param item The context menu item that was selected.
1246cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @return boolean Return false to allow normal context menu processing to
1247cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *         proceed, true to consume it here.
1248cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1249cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public boolean onContextItemSelected(MenuItem item) {
1250cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        return false;
1251cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1252cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
1253cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    /**
1254cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * Print the Fragments's state into the given stream.
1255cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     *
1256cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param prefix Text to print at the front of each line.
1257cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param fd The raw file descriptor that the dump is being sent to.
1258cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param writer The PrintWriter to which you should dump your state.  This will be
1259cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * closed for you after you return.
1260cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     * @param args additional arguments to the dump request.
1261cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn     */
1262cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
1263cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mFragmentId=#");
1264cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mFragmentId));
1265cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mContainerId#=");
1266cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(Integer.toHexString(mContainerId));
1267cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mTag="); writer.println(mTag);
1268cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mState="); writer.print(mState);
1269cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mIndex="); writer.print(mIndex);
1270cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mWho="); writer.print(mWho);
1271cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mBackStackNesting="); writer.println(mBackStackNesting);
1272cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mAdded="); writer.print(mAdded);
1273cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mRemoving="); writer.print(mRemoving);
1274cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mResumed="); writer.print(mResumed);
1275cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mFromLayout="); writer.print(mFromLayout);
1276cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mInLayout="); writer.println(mInLayout);
1277cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
1278e4417c91a0bb2fba42a0aaa99edcca1b238af21aDianne Hackborn                writer.print(" mDetached="); writer.print(mDetached);
12792a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn                writer.print(" mMenuVisible="); writer.print(mMenuVisible);
1280cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                writer.print(" mHasMenu="); writer.println(mHasMenu);
12812a4d8518f36346ea25a22a736453ff28f2954165Dianne Hackborn        writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance);
128279398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mRetaining="); writer.print(mRetaining);
128379398eaefea45e61d839cf4e0534f0eafee70a09Adam Powell                writer.print(" mUserVisibleHint="); writer.println(mUserVisibleHint);
1284cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mFragmentManager != null) {
1285cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mFragmentManager=");
1286cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mFragmentManager);
1287cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1288cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mActivity != null) {
1289cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mActivity=");
1290cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mActivity);
1291cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1292cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mArguments != null) {
1293cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mArguments="); writer.println(mArguments);
1294cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1295cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedFragmentState != null) {
1296cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedFragmentState=");
1297cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedFragmentState);
1298cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1299cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mSavedViewState != null) {
1300cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mSavedViewState=");
1301cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mSavedViewState);
1302cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1303cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mTarget != null) {
1304cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mTarget="); writer.print(mTarget);
1305cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.print(" mTargetRequestCode=");
1306cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mTargetRequestCode);
1307cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1308cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mNextAnim != 0) {
1309cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mNextAnim="); writer.println(mNextAnim);
1310cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1311cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mContainer != null) {
1312cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mContainer="); writer.println(mContainer);
1313cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1314cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mView != null) {
1315cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mView="); writer.println(mView);
1316cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1317cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mInnerView != null) {
1318cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mInnerView="); writer.println(mView);
1319cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1320cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mAnimatingAway != null) {
1321cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mAnimatingAway="); writer.println(mAnimatingAway);
1322cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.print("mStateAfterAnimating=");
1323cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    writer.println(mStateAfterAnimating);
1324cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1325cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoaderManager != null) {
1326cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            writer.print(prefix); writer.println("Loader Manager:");
1327cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoaderManager.dump(prefix + "  ", fd, writer, args);
1328cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1329cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
1330cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn
13319c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performStart() {
13329c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onStart();
13339c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        if (mLoaderManager != null) {
13349c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn            mLoaderManager.doReportStart();
13359c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        }
13369c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
13379c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
1338cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    void performStop() {
1339cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        onStop();
1340681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn    }
1341681a6fb06bdedb8661a68a1b9e34727b6059aa39Dianne Hackborn
1342218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn    void performReallyStop() {
1343cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        if (mLoadersStarted) {
1344cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            mLoadersStarted = false;
1345cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (!mCheckedForLoaderManager) {
1346cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mCheckedForLoaderManager = true;
1347cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false);
1348cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1349cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            if (mLoaderManager != null) {
1350218c1e661578e2a17928f7dbb590b43d1c79aeb7Dianne Hackborn                if (!mActivity.mRetaining) {
1351cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mLoaderManager.doStop();
1352cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                } else {
1353cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                    mLoaderManager.doRetain();
1354cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn                }
1355cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn            }
1356cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn        }
1357cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn    }
13589c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn
13599c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    void performDestroyView() {
13609c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        onDestroyView();
13619c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        if (mLoaderManager != null) {
13629c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn            mLoaderManager.doReportNextStart();
13639c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn        }
13649c53b844bd525e6a04e17291efc38713893074cdDianne Hackborn    }
1365cba2e2c881e8e16ea5025b564c94320174d65f01Dianne Hackborn}
1366