Fragment.java revision 3f00be5bd0b46e7937b68909baeff295b86215cc
12dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn/* 22dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * Copyright (C) 2010 The Android Open Source Project 32dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * 42dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 52dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * you may not use this file except in compliance with the License. 62dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * You may obtain a copy of the License at 72dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * 82dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 92dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * 102dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * Unless required by applicable law or agreed to in writing, software 112dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 122dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * See the License for the specific language governing permissions and 142dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * limitations under the License. 152dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn */ 162dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 172dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackbornpackage android.app; 182dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 19811ed1065f39469cf2cf6adba22cab397ed88d5eChet Haaseimport android.animation.Animatable; 202dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackbornimport android.content.ComponentCallbacks; 21b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackbornimport android.content.Context; 226e8304e57ec533e257a2496183125f257be1ff60Dianne Hackbornimport android.content.Intent; 232dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackbornimport android.content.res.Configuration; 242dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackbornimport android.os.Bundle; 25b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackbornimport android.os.Parcel; 26b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackbornimport android.os.Parcelable; 27b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackbornimport android.util.AndroidRuntimeException; 28ba51c3d02d08709e933de6f6c76dee3fd2f4bfa1Dianne Hackbornimport android.util.AttributeSet; 295e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackbornimport android.util.Log; 30b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackbornimport android.util.SparseArray; 315ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.view.ContextMenu; 322dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackbornimport android.view.LayoutInflater; 33b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackbornimport android.view.Menu; 34b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackbornimport android.view.MenuInflater; 35b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackbornimport android.view.MenuItem; 362dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackbornimport android.view.View; 372dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackbornimport android.view.ViewGroup; 385ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.view.ContextMenu.ContextMenuInfo; 395ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.view.View.OnCreateContextMenuListener; 405ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornimport android.widget.AdapterView; 412dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 42b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackbornimport java.util.HashMap; 43b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 44b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackbornfinal class FragmentState implements Parcelable { 45b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn final String mClassName; 466e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn final int mIndex; 47b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn final boolean mFromLayout; 48b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn final int mFragmentId; 49b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn final int mContainerId; 50b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn final String mTag; 51b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn final boolean mRetainInstance; 52b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn final Bundle mArguments; 53b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 54b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn Bundle mSavedFragmentState; 55b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 56b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn Fragment mInstance; 57b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 58b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public FragmentState(Fragment frag) { 59b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mClassName = frag.getClass().getName(); 606e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mIndex = frag.mIndex; 61b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mFromLayout = frag.mFromLayout; 62b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mFragmentId = frag.mFragmentId; 63b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mContainerId = frag.mContainerId; 64b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mTag = frag.mTag; 65b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mRetainInstance = frag.mRetainInstance; 66b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn mArguments = frag.mArguments; 67b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 68b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 69b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public FragmentState(Parcel in) { 70b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mClassName = in.readString(); 716e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mIndex = in.readInt(); 72b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mFromLayout = in.readInt() != 0; 73b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mFragmentId = in.readInt(); 74b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mContainerId = in.readInt(); 75b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mTag = in.readString(); 76b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mRetainInstance = in.readInt() != 0; 77b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn mArguments = in.readBundle(); 78b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mSavedFragmentState = in.readBundle(); 79b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 80b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 81b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public Fragment instantiate(Activity activity) { 82b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn if (mInstance != null) { 83b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return mInstance; 84b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 85b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 86b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn mInstance = Fragment.instantiate(activity, mClassName, mArguments); 87b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 88b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn if (mSavedFragmentState != null) { 89b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mSavedFragmentState.setClassLoader(activity.getClassLoader()); 90b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mInstance.mSavedFragmentState = mSavedFragmentState; 91b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 926e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mInstance.setIndex(mIndex); 936e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mInstance.mFromLayout = mFromLayout; 94b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mInstance.mFragmentId = mFragmentId; 95b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mInstance.mContainerId = mContainerId; 96b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mInstance.mTag = mTag; 97b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mInstance.mRetainInstance = mRetainInstance; 98b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 99b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return mInstance; 100b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 101b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 102b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public int describeContents() { 103b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return 0; 104b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 105b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 106b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public void writeToParcel(Parcel dest, int flags) { 107b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn dest.writeString(mClassName); 1086e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn dest.writeInt(mIndex); 109b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn dest.writeInt(mFromLayout ? 1 : 0); 110b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn dest.writeInt(mFragmentId); 111b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn dest.writeInt(mContainerId); 112b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn dest.writeString(mTag); 113b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn dest.writeInt(mRetainInstance ? 1 : 0); 114b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn dest.writeBundle(mArguments); 115b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn dest.writeBundle(mSavedFragmentState); 116b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 117b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 118b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public static final Parcelable.Creator<FragmentState> CREATOR 119b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn = new Parcelable.Creator<FragmentState>() { 120b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public FragmentState createFromParcel(Parcel in) { 121b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return new FragmentState(in); 122b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 123b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 124b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public FragmentState[] newArray(int size) { 125b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return new FragmentState[size]; 126b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 127b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn }; 128b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn} 129b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 1302dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn/** 1312dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * A Fragment is a piece of an application's user interface or behavior 1322dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn * that can be placed in an {@link Activity}. 1332dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn */ 1345ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackbornpublic class Fragment implements ComponentCallbacks, OnCreateContextMenuListener { 135c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn private static final HashMap<String, Class<?>> sClassMap = 136c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn new HashMap<String, Class<?>>(); 137b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 138c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn static final int INITIALIZING = 0; // Not yet created. 139c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn static final int CREATED = 1; // Created. 140c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn static final int ACTIVITY_CREATED = 2; // The activity has finished its creation. 141c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn static final int STARTED = 3; // Created and started, not resumed. 142c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn static final int RESUMED = 4; // Created started and resumed. 1432dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 1442dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn int mState = INITIALIZING; 145b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 146b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // When instantiated from saved state, this is the saved state. 147b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn Bundle mSavedFragmentState; 148b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn SparseArray<Parcelable> mSavedViewState; 149b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 1506e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn // Index into active fragment array. 1516e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn int mIndex = -1; 1526e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 1536e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn // Internal unique name for this fragment; 1546e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn String mWho; 1556e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 156b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn // Construction arguments; 157b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn Bundle mArguments; 158b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn 159def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn // Target fragment. 160def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn Fragment mTarget; 161def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn 162def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn // Target request code. 163def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn int mTargetRequestCode; 164def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn 1656e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn // True if the fragment is in the list of added fragments. 1666e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn boolean mAdded; 1676e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 1682707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn // True if the fragment is in the resumed state. 1692707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn boolean mResumed; 1702707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn 171b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // Set to true if this fragment was instantiated from a layout file. 172b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn boolean mFromLayout; 173b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 174b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // Number of active back stack entries this fragment is in. 175f121be737c59390d97e21a92be8e166001534c7dDianne Hackborn int mBackStackNesting; 176b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 177b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn // Set as soon as a fragment is added to a transaction (or removed), 178b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn // to be able to do validation. 179b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn Activity mImmediateActivity; 180b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn 181b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // Activity this fragment is attached to. 1822dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn Activity mActivity; 1832dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 184b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // The optional identifier for this fragment -- either the container ID if it 185b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // was dynamically added to the view hierarchy, or the ID supplied in 186b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // layout. 187b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn int mFragmentId; 188b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 189b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // When a fragment is being dynamically added to the view hierarchy, this 190b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // is the identifier of the parent container it is being added to. 1912dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn int mContainerId; 1922dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 193b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // The optional named tag for this fragment -- usually used to find 194b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // fragments that are not part of the layout. 195b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn String mTag; 196b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 1975ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn // Set to true when the app has requested that this fragment be hidden 1985ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn // from the user. 1995ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn boolean mHidden; 2005ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 201b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // If set this fragment would like its instance retained across 202b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // configuration changes. 203b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn boolean mRetainInstance; 204b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 205b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // If set this fragment is being retained across the current config change. 206b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn boolean mRetaining; 207b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 208b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn // If set this fragment has menu items to contribute. 209b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn boolean mHasMenu; 210b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn 211b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // Used to verify that subclasses call through to super class. 212b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn boolean mCalled; 213b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 2145ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn // If app has requested a specific animation, this is the one to use. 2155ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn int mNextAnim; 2165ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 217b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // The parent container of the fragment after dynamically added to UI. 2182dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn ViewGroup mContainer; 219b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 220b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn // The View generated for this fragment. 2212dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn View mView; 2222dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 2234911b783aa9f4af5ac919db861751d350471f5efDianne Hackborn LoaderManagerImpl mLoaderManager; 224c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn boolean mStarted; 2255e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn boolean mCheckedForLoaderManager; 226c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn 227c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn /** 228b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 229b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * there is an instantiation failure. 230b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn */ 231b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn static public class InstantiationException extends AndroidRuntimeException { 232b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn public InstantiationException(String msg, Exception cause) { 233b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn super(msg, cause); 234b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 235b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 236b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn 237b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn /** 238c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * Default constructor. <strong>Every</string> fragment must have an 239c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * empty constructor, so it can be instantiated when restoring its 240c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * activity's state. It is strongly recommended that subclasses do not 241c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * have other constructors with parameters, since these constructors 242c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * will not be called when the fragment is re-instantiated; instead, 243b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * arguments can be supplied by the caller with {@link #setArguments} 244b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * and later retrieved by the Fragment with {@link #getArguments}. 245b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * 246b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * <p>The first place where application code should generally run is in 247b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * {@link #onAttach(Activity)}, which is the point where the fragment is 248b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * actually attached to its activity and thus capable of doing most 249c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * retrieve such parameters from the activity in {@link #onAttach(Activity)}. 250c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn */ 2512dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public Fragment() { 2522dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 253b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 254b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn /** 255b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * Like {@link #instantiate(Context, String, Bundle)} but with a null 256b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * argument Bundle. 257b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn */ 258b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn public static Fragment instantiate(Context context, String fname) { 259b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn return instantiate(context, fname, null); 260b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 261b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn 262b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn /** 263b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn * Create a new instance of a Fragment with the given class name. This is 264b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn * the same as calling its empty constructor. 265b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn * 266b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn * @param context The calling context being used to instantiate the fragment. 267b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn * This is currently just used to get its ClassLoader. 268b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn * @param fname The class name of the fragment to instantiate. 269b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * @param args Bundle of arguments to supply to the fragment, which it 270b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * can retrieve with {@link #getArguments()}. May be null. 271b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn * @return Returns a new fragment instance. 272b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * @throws InstantiationException If there is a failure in instantiating 273b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * the given fragment class. This is a runtime exception; it is not 274b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * normally expected to happen. 275b1ad5977bc8178b6d350ebe9099daded4c1ef603Dianne Hackborn */ 276b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn public static Fragment instantiate(Context context, String fname, Bundle args) { 277b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn try { 278b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn Class<?> clazz = sClassMap.get(fname); 279b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn if (clazz == null) { 280b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn // Class not found in the cache, see if it's real, and try to add it 281b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn clazz = context.getClassLoader().loadClass(fname); 282b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn sClassMap.put(fname, clazz); 283b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 284b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn Fragment f = (Fragment)clazz.newInstance(); 285b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn if (args != null) { 286b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn args.setClassLoader(f.getClass().getClassLoader()); 287b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn f.mArguments = args; 288b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 289b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn return f; 290b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } catch (ClassNotFoundException e) { 291b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 292b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn + ": make sure class name exists, is public, and has an" 293b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn + " empty constructor that is public", e); 294b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } catch (java.lang.InstantiationException e) { 295b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 296b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn + ": make sure class name exists, is public, and has an" 297b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn + " empty constructor that is public", e); 298b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } catch (IllegalAccessException e) { 299b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn throw new InstantiationException("Unable to instantiate fragment " + fname 300b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn + ": make sure class name exists, is public, and has an" 301b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn + " empty constructor that is public", e); 302b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 303b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 304b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 305b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn void restoreViewState() { 306b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn if (mSavedViewState != null) { 307b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mView.restoreHierarchyState(mSavedViewState); 308b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mSavedViewState = null; 309b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 310b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 311b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 3126e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn void setIndex(int index) { 3136e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mIndex = index; 3146e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mWho = "android:fragment:" + mIndex; 3156e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn } 3166e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 3176e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn void clearIndex() { 3186e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mIndex = -1; 3196e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mWho = null; 3206e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn } 3216e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 322b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 323b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Subclasses can not override equals(). 324b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 325b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn @Override final public boolean equals(Object o) { 326b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return super.equals(o); 327b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 328b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 329b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 330b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Subclasses can not override hashCode(). 331b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 332b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn @Override final public int hashCode() { 333b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return super.hashCode(); 334b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 3352dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 3365ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn @Override 3375ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn public String toString() { 3385ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn StringBuilder sb = new StringBuilder(128); 3395ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append("Fragment{"); 3405ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append(Integer.toHexString(System.identityHashCode(this))); 3415ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn if (mIndex >= 0) { 3425ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append(" #"); 3435ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append(mIndex); 3445ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 3455ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn if (mFragmentId != 0) { 3465ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append(" id=0x"); 3475ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append(Integer.toHexString(mFragmentId)); 3485ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 3495ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn if (mTag != null) { 3505ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append(" "); 3515ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append(mTag); 3525ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 3535ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn sb.append('}'); 3545ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn return sb.toString(); 3555ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 3565ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 357b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 358b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Return the identifier this fragment is known by. This is either 359b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * the android:id value supplied in a layout or the container view ID 360b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * supplied when adding the fragment. 361b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 362b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn final public int getId() { 363b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return mFragmentId; 364b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 365b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 366b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 367b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Get the tag name of the fragment, if specified. 368b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 369b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn final public String getTag() { 370b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return mTag; 371b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 372b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 373b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 374b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * Supply the construction arguments for this fragment. This can only 375b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * be called before the fragment has been attached to its activity; that 376b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * is, you should call it immediately after constructing the fragment. The 377b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * arguments supplied here will be retained across fragment destroy and 378b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * creation. 379b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn */ 380def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn public void setArguments(Bundle args) { 381b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn if (mIndex >= 0) { 382b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn throw new IllegalStateException("Fragment already active"); 383b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 384b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn mArguments = args; 385b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 386b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn 387b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn /** 388b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * Return the arguments supplied when the fragment was instantiated, 389b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * if any. 390b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn */ 391b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn final public Bundle getArguments() { 392b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn return mArguments; 393b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 394b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn 395b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn /** 396def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * Optional target for this fragment. This may be used, for example, 397def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * if this fragment is being started by another, and when done wants to 398def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * give a result back to the first. The target set here is retained 399def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * across instances via {@link FragmentManager#putFragment 400def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * FragmentManager.putFragment()}. 401def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * 402def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * @param fragment The fragment that is the target of this one. 403def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * @param requestCode Optional request code, for convenience if you 404def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * are going to call back with {@link #onActivityResult(int, int, Intent)}. 405def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn */ 406def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn public void setTargetFragment(Fragment fragment, int requestCode) { 407def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn mTarget = fragment; 408def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn mTargetRequestCode = requestCode; 409def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn } 410def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn 411def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn /** 4123f00be5bd0b46e7937b68909baeff295b86215ccDianne Hackborn * Return the target fragment set by {@link #setTargetFragment}. 413def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn */ 414def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn final public Fragment getTargetFragment() { 415def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn return mTarget; 416def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn } 417def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn 418def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn /** 4193f00be5bd0b46e7937b68909baeff295b86215ccDianne Hackborn * Return the target request code set by {@link #setTargetFragment}. 420def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn */ 421def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn final public int getTargetRequestCode() { 422def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn return mTargetRequestCode; 423def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn } 424def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn 425def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn /** 426b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Return the Activity this fragment is currently associated with. 427b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 428b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn final public Activity getActivity() { 4292dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn return mActivity; 4302dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 4312dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 432b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 433b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * Return the FragmentManager for interacting with fragments associated 434b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn * with this fragment's activity. 435b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn */ 436b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn final public FragmentManager getFragmentManager() { 437b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn return mActivity.mFragments; 438b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn } 439b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn 440b7a2e4772220c4b41df1260cedaf8912f4b07547Dianne Hackborn /** 4415ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * Return true if the fragment is currently added to its activity. 4425ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn */ 443b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn final public boolean isAdded() { 4445ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn return mActivity != null && mActivity.mFragments.mAdded.contains(this); 4455ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 4465ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 4475ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn /** 4482707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn * Return true if the fragment is in the resumed state. This is true 4492707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn * for the duration of {@link #onResume()} and {@link #onPause()} as well. 4502707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn */ 4512707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn final public boolean isResumed() { 4522707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn return mResumed; 4532707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn } 4542707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn 4552707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn /** 4565ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * Return true if the fragment is currently visible to the user. This means 4575ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * it: (1) has been added, (2) has its view attached to the window, and 4585ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * (3) is not hidden. 4595ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn */ 460b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn final public boolean isVisible() { 4615ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn return isAdded() && !isHidden() && mView != null 4625ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 4635ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 4645ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 4655ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn /** 4665ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * Return true if the fragment has been hidden. By default fragments 4675ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * are shown. You can find out about changes to this state with 468cddfa6de1fcf1a9480d4c9b575102909bd8f2067Dianne Hackborn * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 4695ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * to other states -- that is, to be visible to the user, a fragment 4705ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * must be both started and not hidden. 4715ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn */ 472b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn final public boolean isHidden() { 4735ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn return mHidden; 4745ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 4755ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 4765ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn /** 4775ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * Called when the hidden state (as returned by {@link #isHidden()} of 4785ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * the fragment has changed. Fragments start out not hidden; this will 4795ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * be called whenever the fragment changes state from that. 4805ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * @param hidden True if the fragment is now hidden, false if it is not 4815ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn * visible. 4825ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn */ 4835ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn public void onHiddenChanged(boolean hidden) { 4845ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn } 4855ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 4865ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn /** 487b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Control whether a fragment instance is retained across Activity 488b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * re-creation (such as from a configuration change). This can only 489b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * be used with fragments not in the back stack. If set, the fragment 490b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * lifecycle will be slightly different when an activity is recreated: 491b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * <ul> 492b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 493b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * will be, because the fragment is being detached from its current activity). 494b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * <li> {@link #onCreate(Bundle)} will not be called since the fragment 495b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * is not being re-created. 496c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 497b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * still be called. 498b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * </ul> 499b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 500b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public void setRetainInstance(boolean retain) { 501b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mRetainInstance = retain; 502b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 503b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 504b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn final public boolean getRetainInstance() { 505b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return mRetainInstance; 506b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 507b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 508b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 509b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * Report that this fragment would like to participate in populating 5104dc643eb6749afe5211198c920e739475590f92cWink Saville * the options menu by receiving a call to {@link #onCreateOptionsMenu} 511b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * and related methods. 512b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 513b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @param hasMenu If true, the fragment has menu items to contribute. 514b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn */ 515b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn public void setHasOptionsMenu(boolean hasMenu) { 516b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn if (mHasMenu != hasMenu) { 517b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn mHasMenu = hasMenu; 518b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn if (isAdded() && !isHidden()) { 519b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn mActivity.invalidateOptionsMenu(); 520b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn } 521b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn } 522b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn } 523b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn 524b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn /** 525c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * Return the LoaderManager for this fragment, creating it if needed. 526c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn */ 527c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn public LoaderManager getLoaderManager() { 528c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn if (mLoaderManager != null) { 529c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn return mLoaderManager; 530c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn } 5315e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mCheckedForLoaderManager = true; 5325e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mIndex, mStarted, true); 533c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn return mLoaderManager; 534c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn } 535c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn 536c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn /** 5376e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * Call {@link Activity#startActivity(Intent)} on the fragment's 5386e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * containing Activity. 5396e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn */ 5406e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn public void startActivity(Intent intent) { 5416e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mActivity.startActivityFromFragment(this, intent, -1); 5426e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn } 5436e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 5446e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn /** 5456e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's 5466e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * containing Activity. 5476e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn */ 5486e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn public void startActivityForResult(Intent intent, int requestCode) { 5496e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn mActivity.startActivityFromFragment(this, intent, requestCode); 5506e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn } 5516e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 5526e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn /** 5536e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * Receive the result from a previous call to 5546e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * {@link #startActivityForResult(Intent, int)}. This follows the 5556e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * related Activity API as described there in 5566e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * {@link Activity#onActivityResult(int, int, Intent)}. 5576e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * 5586e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * @param requestCode The integer request code originally supplied to 5596e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * startActivityForResult(), allowing you to identify who this 5606e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * result came from. 5616e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * @param resultCode The integer result code returned by the child activity 5626e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * through its setResult(). 5636e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * @param data An Intent, which can return result data to the caller 5646e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * (various data can be attached to Intent "extras"). 5656e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn */ 5666e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn public void onActivityResult(int requestCode, int resultCode, Intent data) { 5676e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn } 5686e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn 5696e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn /** 570b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when a fragment is being created as part of a view layout 5716e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * inflation, typically from setting the content view of an activity. This 572def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * will be called immediately after the fragment is created from a <fragment> 573def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * tag in a layout file. Note this is <em>before</em> the fragment's 574def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * {@link #onAttach(Activity)} has been called; all you should do here is 575def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * parse the attributes and save them away. A convenient thing to do is 576def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * simply copy them into a Bundle that is given to {@link #setArguments(Bundle)}. 5776e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * 578def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * <p>This is called every time the fragment is inflated, even if it is 579def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * being inflated into a new instance with saved state. Because a fragment's 580def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * arguments are retained across instances, it may make no sense to re-parse 581def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * the attributes into new arguments. You may want to first check 582def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * {@link #getArguments()} and only parse the attributes if it returns null, 583def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * the assumption being that if it is non-null those are the same arguments 584def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * from the first time the fragment was inflated. (That said, you may want 585def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * to have layouts change for different configurations such as landscape 586def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * and portrait, which can have different attributes. If so, you will need 587def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * to re-parse the attributes each time this is called to generate new 588def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * arguments.)</p> 589b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * 590b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * @param attrs The attributes at the tag where the fragment is 591b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * being created. 5926e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 5936e8304e57ec533e257a2496183125f257be1ff60Dianne Hackborn * a previous saved state, this is the state. 594b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 595def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn public void onInflate(AttributeSet attrs, Bundle savedInstanceState) { 596ba51c3d02d08709e933de6f6c76dee3fd2f4bfa1Dianne Hackborn mCalled = true; 597ba51c3d02d08709e933de6f6c76dee3fd2f4bfa1Dianne Hackborn } 598ba51c3d02d08709e933de6f6c76dee3fd2f4bfa1Dianne Hackborn 599b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 600b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when a fragment is first attached to its activity. 601b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * {@link #onCreate(Bundle)} will be called after this. 602b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 6032dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onAttach(Activity activity) { 6042dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 6052dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 6062dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 607811ed1065f39469cf2cf6adba22cab397ed88d5eChet Haase /** 608811ed1065f39469cf2cf6adba22cab397ed88d5eChet Haase * Called when a fragment loads an animation. 609811ed1065f39469cf2cf6adba22cab397ed88d5eChet Haase */ 610811ed1065f39469cf2cf6adba22cab397ed88d5eChet Haase public Animatable onCreateAnimatable(int transit, boolean enter, int nextAnim) { 611f121be737c59390d97e21a92be8e166001534c7dDianne Hackborn return null; 612f121be737c59390d97e21a92be8e166001534c7dDianne Hackborn } 613f121be737c59390d97e21a92be8e166001534c7dDianne Hackborn 614b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 615b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called to do initial creation of a fragment. This is called after 616c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * {@link #onAttach(Activity)} and before 617c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 618c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * 619c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * <p>Note that this can be called while the fragment's activity is 620c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * still in the process of being created. As such, you can not rely 621c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * on things like the activity's content view hierarchy being initialized 622c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * at this point. If you want to do work once the activity itself is 623c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * created, see {@link #onActivityCreated(Bundle)}. 624c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * 625b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 626b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * a previous saved state, this is the state. 627b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 6282dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onCreate(Bundle savedInstanceState) { 6292dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 6302dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 6312dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 632b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 633b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called to have the fragment instantiate its user interface view. 634b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * This is optional, and non-graphical fragments can return null (which 635b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * is the default implementation). This will be called between 636c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 637b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * 6385ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p>If you return a View from here, you will later be called in 6395ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@link #onDestroyView} when the view is being released. 6405ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 641b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * @param inflater The LayoutInflater object that can be used to inflate 642b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * any views in the fragment, 643b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * @param container If non-null, this is the parent view that the fragment's 644b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * UI should be attached to. The fragment should not add the view itself, 645b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * but this can be used to generate the LayoutParams of the view. 646b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * @param savedInstanceState If non-null, this fragment is being re-constructed 647b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * from a previous saved state as given here. 648b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * 649b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * @return Return the View for the fragment's UI, or null. 650b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 651b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public View onCreateView(LayoutInflater inflater, ViewGroup container, 652b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn Bundle savedInstanceState) { 6532dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn return null; 6542dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 6552dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 656b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn public View getView() { 657b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn return mView; 658b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn } 659b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn 660b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 661c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * Called when the fragment's activity has been created and this 662c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * fragment's view hierarchy instantiated. It can be used to do final 663c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * initialization once these pieces are in place, such as retrieving 664c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * views or restoring state. It is also useful for fragments that use 665c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * {@link #setRetainInstance(boolean)} to retain their instance, 666c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn * as this callback tells the fragment when it is fully associated with 6675ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * the new activity instance. This is called after {@link #onCreateView} 668b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * and before {@link #onStart()}. 669b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * 670b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * @param savedInstanceState If the fragment is being re-created from 671b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * a previous saved state, this is the state. 672b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 673c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn public void onActivityCreated(Bundle savedInstanceState) { 674b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn mCalled = true; 6752dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 6762dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 677b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 678b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when the Fragment is visible to the user. This is generally 679b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * tied to {@link Activity#onStart() Activity.onStart} of the containing 680b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Activity's lifecycle. 681b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 6822dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onStart() { 6832dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 684c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn mStarted = true; 6855e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn if (!mCheckedForLoaderManager) { 6865e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mCheckedForLoaderManager = true; 6875e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mIndex, mStarted, false); 6885e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn } 689c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn if (mLoaderManager != null) { 690c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn mLoaderManager.doStart(); 691c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn } 6922dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 6932dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 694b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 695b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when the fragment is visible to the user and actively running. 696b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * This is generally 697b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * tied to {@link Activity#onResume() Activity.onResume} of the containing 698b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Activity's lifecycle. 699b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 7002dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onResume() { 7012dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 7022dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 7032dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 7042dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onSaveInstanceState(Bundle outState) { 7052dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 7062dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 7072dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onConfigurationChanged(Configuration newConfig) { 7082dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 7092dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 7102dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 711b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 712b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when the Fragment is no longer resumed. This is generally 713b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * tied to {@link Activity#onPause() Activity.onPause} of the containing 714b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Activity's lifecycle. 715b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 7162dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onPause() { 7172dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 7182dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 7192dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 720b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 721b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when the Fragment is no longer started. This is generally 722b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * tied to {@link Activity#onStop() Activity.onStop} of the containing 723b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Activity's lifecycle. 724b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 7252dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onStop() { 7262dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 7272dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 7282dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 7292dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onLowMemory() { 7302dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 7312dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 7322dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn 733b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 7345ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Called when the view previously created by {@link #onCreateView} has 7355ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * been detached from the fragment. The next time the fragment needs 7365ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * to be displayed, a new view will be created. This is called 737def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * after {@link #onStop()} and before {@link #onDestroy()}. It is called 738def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * <em>regardless</em> of whether {@link #onCreateView} returned a 739def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * non-null view. Internally it is called after the view's state has 740def1537e9e8d0dd190cde5310ddae8b921088c9bDianne Hackborn * been saved but before it has been removed from its parent. 7415ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 7425ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void onDestroyView() { 7435ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn mCalled = true; 7445ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 7455ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 7465ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 747b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when the fragment is no longer in use. This is called 748b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * after {@link #onStop()} and before {@link #onDetach()}. 749b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 7502dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onDestroy() { 7512dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 7525e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager 7535e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn // + " mLoaderManager=" + mLoaderManager); 7545e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn if (!mCheckedForLoaderManager) { 7555e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mCheckedForLoaderManager = true; 7565e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mIndex, mStarted, false); 7575e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn } 758c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn if (mLoaderManager != null) { 759c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn mLoaderManager.doDestroy(); 760c801768e4d29667a2608695449ebc2833ba0f200Dianne Hackborn } 7612dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 7625ae74d6e89a30e79ea85c487b32223ef55314985Dianne Hackborn 763b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn /** 764b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * Called when the fragment is no longer attached to its activity. This 765b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn * is called after {@link #onDestroy()}. 766b4bc78b16a05554c57508b488e21dd8eca4e13e6Dianne Hackborn */ 7672dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn public void onDetach() { 7682dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn mCalled = true; 7692dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn } 770b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn 771b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn /** 772b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * Initialize the contents of the Activity's standard options menu. You 773b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * should place your menu items in to <var>menu</var>. For this method 7745ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * to be called, you must have first called {@link #setHasOptionsMenu}. See 7755ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 7765ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * for more information. 777b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 778b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @param menu The options menu in which you place your items. 779b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 7804dc643eb6749afe5211198c920e739475590f92cWink Saville * @see #setHasOptionsMenu 781b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @see #onPrepareOptionsMenu 782b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @see #onOptionsItemSelected 783b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn */ 784b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 785b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn } 786b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn 787b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn /** 788b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * Prepare the Screen's standard options menu to be displayed. This is 789b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * called right before the menu is shown, every time it is shown. You can 790b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * use this method to efficiently enable/disable items or otherwise 791b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * dynamically modify the contents. See 792b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 793b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * for more information. 794b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 795b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @param menu The options menu as last shown or first initialized by 796b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * onCreateOptionsMenu(). 797b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 7984dc643eb6749afe5211198c920e739475590f92cWink Saville * @see #setHasOptionsMenu 799b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @see #onCreateOptionsMenu 800b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn */ 801b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn public void onPrepareOptionsMenu(Menu menu) { 802b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn } 803b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn 804b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn /** 805b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * This hook is called whenever an item in your options menu is selected. 806b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * The default implementation simply returns false to have the normal 807b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * processing happen (calling the item's Runnable or sending a message to 808b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * its Handler as appropriate). You can use this method for any items 809b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * for which you would like to do processing without those other 810b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * facilities. 811b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 812b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * <p>Derived classes should call through to the base class for it to 813b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * perform the default menu handling. 814b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 815b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @param item The menu item that was selected. 816b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 817b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @return boolean Return false to allow normal menu processing to 818b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * proceed, true to consume it here. 819b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 820b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @see #onCreateOptionsMenu 821b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn */ 822b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn public boolean onOptionsItemSelected(MenuItem item) { 823b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn return false; 824b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn } 825b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn 826b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn /** 827b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * This hook is called whenever the options menu is being closed (either by the user canceling 828b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * the menu with the back/menu button, or when an item is selected). 829b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * 830b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * @param menu The options menu as last shown or first initialized by 831b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn * onCreateOptionsMenu(). 832b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn */ 833b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn public void onOptionsMenuClosed(Menu menu) { 834b31e84bc4513e46bac4be8f8d0513f78e360fb11Dianne Hackborn } 8355ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 8365ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 8375ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Called when a context menu for the {@code view} is about to be shown. 8385ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Unlike {@link #onCreateOptionsMenu}, this will be called every 8395ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * time the context menu is about to be shown and should be populated for 8405ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * the view (or item inside the view for {@link AdapterView} subclasses, 8415ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * this can be found in the {@code menuInfo})). 8425ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 8435ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 8445ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * item has been selected. 8455ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 8465ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * The default implementation calls up to 8475ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 8485ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * you can not call this implementation if you don't want that behavior. 8495ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 8505ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * It is not safe to hold onto the context menu after this method returns. 8515ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@inheritDoc} 8525ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 8535ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 8545ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn getActivity().onCreateContextMenu(menu, v, menuInfo); 8555ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 8565ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 8575ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 8585ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Registers a context menu to be shown for the given view (multiple views 8595ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * can show the context menu). This method will set the 8605ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@link OnCreateContextMenuListener} on the view to this fragment, so 8615ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 8625ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * called when it is time to show the context menu. 8635ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 8645ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @see #unregisterForContextMenu(View) 8655ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param view The view that should show a context menu. 8665ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 8675ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void registerForContextMenu(View view) { 8685ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn view.setOnCreateContextMenuListener(this); 8695ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 8705ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 8715ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 8725ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Prevents a context menu to be shown for the given view. This method will 8735ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * remove the {@link OnCreateContextMenuListener} on the view. 8745ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 8755ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @see #registerForContextMenu(View) 8765ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param view The view that should stop showing a context menu. 8775ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 8785ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public void unregisterForContextMenu(View view) { 8795ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn view.setOnCreateContextMenuListener(null); 8805ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 8815ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn 8825ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn /** 8835ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * This hook is called whenever an item in a context menu is selected. The 8845ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * default implementation simply returns false to have the normal processing 8855ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * happen (calling the item's Runnable or sending a message to its Handler 8865ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * as appropriate). You can use this method for any items for which you 8875ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * would like to do processing without those other facilities. 8885ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 8895ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 8905ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * View that added this menu item. 8915ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * <p> 8925ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * Derived classes should call through to the base class for it to perform 8935ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * the default menu handling. 8945ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * 8955ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @param item The context menu item that was selected. 8965ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * @return boolean Return false to allow normal context menu processing to 8975ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn * proceed, true to consume it here. 8985ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn */ 8995ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn public boolean onContextItemSelected(MenuItem item) { 9005ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn return false; 9015ddd127d5a38d80c0d8087d1770f41f61f84f048Dianne Hackborn } 9022707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn 9032707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn void performStop() { 9042707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn onStop(); 9052707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn if (mStarted) { 9062707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn mStarted = false; 9075e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn if (!mCheckedForLoaderManager) { 9085e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mCheckedForLoaderManager = true; 9095e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn mLoaderManager = mActivity.getLoaderManager(mIndex, mStarted, false); 9105e0d59547c4042037e23a42ba4e2521721e9c7d3Dianne Hackborn } 9112707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn if (mLoaderManager != null) { 9122707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn if (mActivity == null || !mActivity.mChangingConfigurations) { 9132707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn mLoaderManager.doStop(); 9142707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn } else { 9152707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn mLoaderManager.doRetain(); 9162707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn } 9172707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn } 9182707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn } 9192707d6026240bcca6f0e35e2e1138958882e90ceDianne Hackborn } 9202dedce6e84679ead961a485c7fe4b0f77c713b6aDianne Hackborn} 921