Fragment.java revision f9dd34f4d3203fd50363b3b0247c5d0db6fe2c8f
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.app; 18 19import android.animation.Animator; 20import android.content.ComponentCallbacks; 21import android.content.Context; 22import android.content.Intent; 23import android.content.res.Configuration; 24import android.content.res.Resources; 25import android.os.Bundle; 26import android.os.Parcel; 27import android.os.Parcelable; 28import android.util.AndroidRuntimeException; 29import android.util.AttributeSet; 30import android.util.DebugUtils; 31import android.util.SparseArray; 32import android.view.ContextMenu; 33import android.view.LayoutInflater; 34import android.view.Menu; 35import android.view.MenuInflater; 36import android.view.MenuItem; 37import android.view.View; 38import android.view.ViewGroup; 39import android.view.ContextMenu.ContextMenuInfo; 40import android.view.View.OnCreateContextMenuListener; 41import android.widget.AdapterView; 42 43import java.io.FileDescriptor; 44import java.io.PrintWriter; 45import java.util.HashMap; 46 47final class FragmentState implements Parcelable { 48 final String mClassName; 49 final int mIndex; 50 final boolean mFromLayout; 51 final int mFragmentId; 52 final int mContainerId; 53 final String mTag; 54 final boolean mRetainInstance; 55 final boolean mDetached; 56 final Bundle mArguments; 57 58 Bundle mSavedFragmentState; 59 60 Fragment mInstance; 61 62 public FragmentState(Fragment frag) { 63 mClassName = frag.getClass().getName(); 64 mIndex = frag.mIndex; 65 mFromLayout = frag.mFromLayout; 66 mFragmentId = frag.mFragmentId; 67 mContainerId = frag.mContainerId; 68 mTag = frag.mTag; 69 mRetainInstance = frag.mRetainInstance; 70 mDetached = frag.mDetached; 71 mArguments = frag.mArguments; 72 } 73 74 public FragmentState(Parcel in) { 75 mClassName = in.readString(); 76 mIndex = in.readInt(); 77 mFromLayout = in.readInt() != 0; 78 mFragmentId = in.readInt(); 79 mContainerId = in.readInt(); 80 mTag = in.readString(); 81 mRetainInstance = in.readInt() != 0; 82 mDetached = in.readInt() != 0; 83 mArguments = in.readBundle(); 84 mSavedFragmentState = in.readBundle(); 85 } 86 87 public Fragment instantiate(Activity activity) { 88 if (mInstance != null) { 89 return mInstance; 90 } 91 92 if (mArguments != null) { 93 mArguments.setClassLoader(activity.getClassLoader()); 94 } 95 96 mInstance = Fragment.instantiate(activity, mClassName, mArguments); 97 98 if (mSavedFragmentState != null) { 99 mSavedFragmentState.setClassLoader(activity.getClassLoader()); 100 mInstance.mSavedFragmentState = mSavedFragmentState; 101 } 102 mInstance.setIndex(mIndex); 103 mInstance.mFromLayout = mFromLayout; 104 mInstance.mRestored = true; 105 mInstance.mFragmentId = mFragmentId; 106 mInstance.mContainerId = mContainerId; 107 mInstance.mTag = mTag; 108 mInstance.mRetainInstance = mRetainInstance; 109 mInstance.mDetached = mDetached; 110 mInstance.mFragmentManager = activity.mFragments; 111 112 return mInstance; 113 } 114 115 public int describeContents() { 116 return 0; 117 } 118 119 public void writeToParcel(Parcel dest, int flags) { 120 dest.writeString(mClassName); 121 dest.writeInt(mIndex); 122 dest.writeInt(mFromLayout ? 1 : 0); 123 dest.writeInt(mFragmentId); 124 dest.writeInt(mContainerId); 125 dest.writeString(mTag); 126 dest.writeInt(mRetainInstance ? 1 : 0); 127 dest.writeInt(mDetached ? 1 : 0); 128 dest.writeBundle(mArguments); 129 dest.writeBundle(mSavedFragmentState); 130 } 131 132 public static final Parcelable.Creator<FragmentState> CREATOR 133 = new Parcelable.Creator<FragmentState>() { 134 public FragmentState createFromParcel(Parcel in) { 135 return new FragmentState(in); 136 } 137 138 public FragmentState[] newArray(int size) { 139 return new FragmentState[size]; 140 } 141 }; 142} 143 144/** 145 * A Fragment is a piece of an application's user interface or behavior 146 * that can be placed in an {@link Activity}. Interaction with fragments 147 * is done through {@link FragmentManager}, which can be obtained via 148 * {@link Activity#getFragmentManager() Activity.getFragmentManager()} and 149 * {@link Fragment#getFragmentManager() Fragment.getFragmentManager()}. 150 * 151 * <p>The Fragment class can be used many ways to achieve a wide variety of 152 * results. It is core, it represents a particular operation or interface 153 * that is running within a larger {@link Activity}. A Fragment is closely 154 * tied to the Activity it is in, and can not be used apart from one. Though 155 * Fragment defines its own lifecycle, that lifecycle is dependent on its 156 * activity: if the activity is stopped, no fragments inside of it can be 157 * started; when the activity is destroyed, all fragments will be destroyed. 158 * 159 * <p>All subclasses of Fragment must include a public empty constructor. 160 * The framework will often re-instantiate a fragment class when needed, 161 * in particular during state restore, and needs to be able to find this 162 * constructor to instantiate it. If the empty constructor is not available, 163 * a runtime exception will occur in some cases during state restore. 164 * 165 * <p>Topics covered here: 166 * <ol> 167 * <li><a href="#OlderPlatforms">Older Platforms</a> 168 * <li><a href="#Lifecycle">Lifecycle</a> 169 * <li><a href="#Layout">Layout</a> 170 * <li><a href="#BackStack">Back Stack</a> 171 * </ol> 172 * 173 * <a name="OlderPlatforms"></a> 174 * <h3>Older Platforms</h3> 175 * 176 * While the Fragment API was introduced in 177 * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, a version of the API 178 * is also available for use on older platforms. See the blog post 179 * <a href="http://android-developers.blogspot.com/2011/03/fragments-for-all.html"> 180 * Fragments For All</a> for more details. 181 * 182 * <a name="Lifecycle"></a> 183 * <h3>Lifecycle</h3> 184 * 185 * <p>Though a Fragment's lifecycle is tied to its owning activity, it has 186 * its own wrinkle on the standard activity lifecycle. It includes basic 187 * activity lifecycle methods such as {@link #onResume}, but also important 188 * are methods related to interactions with the activity and UI generation. 189 * 190 * <p>The core series of lifecycle methods that are called to bring a fragment 191 * up to resumed state (interacting with the user) are: 192 * 193 * <ol> 194 * <li> {@link #onAttach} called once the fragment is associated with its activity. 195 * <li> {@link #onCreate} called to do initial creation of the fragment. 196 * <li> {@link #onCreateView} creates and returns the view hierarchy associated 197 * with the fragment. 198 * <li> {@link #onActivityCreated} tells the fragment that its activity has 199 * completed its own {@link Activity#onCreate Activity.onCreaate}. 200 * <li> {@link #onStart} makes the fragment visible to the user (based on its 201 * containing activity being started). 202 * <li> {@link #onResume} makes the fragment interacting with the user (based on its 203 * containing activity being resumed). 204 * </ol> 205 * 206 * <p>As a fragment is no longer being used, it goes through a reverse 207 * series of callbacks: 208 * 209 * <ol> 210 * <li> {@link #onPause} fragment is no longer interacting with the user either 211 * because its activity is being paused or a fragment operation is modifying it 212 * in the activity. 213 * <li> {@link #onStop} fragment is no longer visible to the user either 214 * because its activity is being stopped or a fragment operation is modifying it 215 * in the activity. 216 * <li> {@link #onDestroyView} allows the fragment to clean up resources 217 * associated with its View. 218 * <li> {@link #onDestroy} called to do final cleanup of the fragment's state. 219 * <li> {@link #onDetach} called immediately prior to the fragment no longer 220 * being associated with its activity. 221 * </ol> 222 * 223 * <a name="Layout"></a> 224 * <h3>Layout</h3> 225 * 226 * <p>Fragments can be used as part of your application's layout, allowing 227 * you to better modularize your code and more easily adjust your user 228 * interface to the screen it is running on. As an example, we can look 229 * at a simple program consisting of a list of items, and display of the 230 * details of each item.</p> 231 * 232 * <p>An activity's layout XML can include <code><fragment></code> tags 233 * to embed fragment instances inside of the layout. For example, here is 234 * a simple layout that embeds one fragment:</p> 235 * 236 * {@sample development/samples/ApiDemos/res/layout/fragment_layout.xml layout} 237 * 238 * <p>The layout is installed in the activity in the normal way:</p> 239 * 240 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java 241 * main} 242 * 243 * <p>The titles fragment, showing a list of titles, is fairly simple, relying 244 * on {@link ListFragment} for most of its work. Note the implementation of 245 * clicking an item: depending on the current activity's layout, it can either 246 * create and display a new fragment to show the details in-place (more about 247 * this later), or start a new activity show the details.</p> 248 * 249 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java 250 * titles} 251 * 252 * <p>The details fragment showing the contents of selected item here just 253 * displays a string of text based on an index of a string array built in to 254 * the app:</p> 255 * 256 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java 257 * details} 258 * 259 * <p>In this case when the user clicks on a title, there is no details 260 * container in the current activity, so the title title fragment's click code will 261 * launch a new activity to display the details fragment:</p> 262 * 263 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentLayout.java 264 * details_activity} 265 * 266 * <p>However the screen may be large enough to show both the list of titles 267 * and details about the currently selected title. To use such a layout on 268 * a landscape screen, this alternative layout can be placed under layout-land:</p> 269 * 270 * {@sample development/samples/ApiDemos/res/layout-land/fragment_layout.xml layout} 271 * 272 * <p>Note how the prior code will adjust to this alternative UI flow: the titles 273 * fragment will now embed the details fragment inside of this activity, and the 274 * details activity will finish itself if it is running in a configuration 275 * where the details can be shown in-place. 276 * 277 * <p>When a configuration change causes the activity hosting these fragments 278 * to restart, its new instance may use a different layout that doesn't 279 * include the same fragments as the previous layout. In this case all of 280 * the previous fragments will still be instantiated and running in the new 281 * instance. However, any that are no longer associated with a <fragment> 282 * tag in the view hierarchy will not have their content view created 283 * and will return false from {@link #isInLayout}. (The code here also shows 284 * how you can determine if a fragment placed in a container is no longer 285 * running in a layout with that container and avoid creating its view hierarchy 286 * in that case.) 287 * 288 * <p>The attributes of the <fragment> tag are used to control the 289 * LayoutParams provided when attaching the fragment's view to the parent 290 * container. They can also be parsed by the fragment in {@link #onInflate} 291 * as parameters. 292 * 293 * <p>The fragment being instantiated must have some kind of unique identifier 294 * so that it can be re-associated with a previous instance if the parent 295 * activity needs to be destroyed and recreated. This can be provided these 296 * ways: 297 * 298 * <ul> 299 * <li>If nothing is explicitly supplied, the view ID of the container will 300 * be used. 301 * <li><code>android:tag</code> can be used in <fragment> to provide 302 * a specific tag name for the fragment. 303 * <li><code>android:id</code> can be used in <fragment> to provide 304 * a specific identifier for the fragment. 305 * </ul> 306 * 307 * <a name="BackStack"></a> 308 * <h3>Back Stack</h3> 309 * 310 * <p>The transaction in which fragments are modified can be placed on an 311 * internal back-stack of the owning activity. When the user presses back 312 * in the activity, any transactions on the back stack are popped off before 313 * the activity itself is finished. 314 * 315 * <p>For example, consider this simple fragment that is instantiated with 316 * an integer argument and displays that in a TextView in its UI:</p> 317 * 318 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentStack.java 319 * fragment} 320 * 321 * <p>A function that creates a new instance of the fragment, replacing 322 * whatever current fragment instance is being shown and pushing that change 323 * on to the back stack could be written as: 324 * 325 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentStack.java 326 * add_stack} 327 * 328 * <p>After each call to this function, a new entry is on the stack, and 329 * pressing back will pop it to return the user to whatever previous state 330 * the activity UI was in. 331 */ 332public class Fragment implements ComponentCallbacks, OnCreateContextMenuListener { 333 private static final HashMap<String, Class<?>> sClassMap = 334 new HashMap<String, Class<?>>(); 335 336 static final int INITIALIZING = 0; // Not yet created. 337 static final int CREATED = 1; // Created. 338 static final int ACTIVITY_CREATED = 2; // The activity has finished its creation. 339 static final int STOPPED = 3; // Fully created, not started. 340 static final int STARTED = 4; // Created and started, not resumed. 341 static final int RESUMED = 5; // Created started and resumed. 342 343 int mState = INITIALIZING; 344 345 // Non-null if the fragment's view hierarchy is currently animating away, 346 // meaning we need to wait a bit on completely destroying it. This is the 347 // animation that is running. 348 Animator mAnimatingAway; 349 350 // If mAnimatingAway != null, this is the state we should move to once the 351 // animation is done. 352 int mStateAfterAnimating; 353 354 // When instantiated from saved state, this is the saved state. 355 Bundle mSavedFragmentState; 356 SparseArray<Parcelable> mSavedViewState; 357 358 // Index into active fragment array. 359 int mIndex = -1; 360 361 // Internal unique name for this fragment; 362 String mWho; 363 364 // Construction arguments; 365 Bundle mArguments; 366 367 // Target fragment. 368 Fragment mTarget; 369 370 // Target request code. 371 int mTargetRequestCode; 372 373 // True if the fragment is in the list of added fragments. 374 boolean mAdded; 375 376 // If set this fragment is being removed from its activity. 377 boolean mRemoving; 378 379 // True if the fragment is in the resumed state. 380 boolean mResumed; 381 382 // Set to true if this fragment was instantiated from a layout file. 383 boolean mFromLayout; 384 385 // Set to true when the view has actually been inflated in its layout. 386 boolean mInLayout; 387 388 // True if this fragment has been restored from previously saved state. 389 boolean mRestored; 390 391 // Number of active back stack entries this fragment is in. 392 int mBackStackNesting; 393 394 // The fragment manager we are associated with. Set as soon as the 395 // fragment is used in a transaction; cleared after it has been removed 396 // from all transactions. 397 FragmentManager mFragmentManager; 398 399 // Set as soon as a fragment is added to a transaction (or removed), 400 // to be able to do validation. 401 Activity mImmediateActivity; 402 403 // Activity this fragment is attached to. 404 Activity mActivity; 405 406 // The optional identifier for this fragment -- either the container ID if it 407 // was dynamically added to the view hierarchy, or the ID supplied in 408 // layout. 409 int mFragmentId; 410 411 // When a fragment is being dynamically added to the view hierarchy, this 412 // is the identifier of the parent container it is being added to. 413 int mContainerId; 414 415 // The optional named tag for this fragment -- usually used to find 416 // fragments that are not part of the layout. 417 String mTag; 418 419 // Set to true when the app has requested that this fragment be hidden 420 // from the user. 421 boolean mHidden; 422 423 // Set to true when the app has requested that this fragment be detached. 424 boolean mDetached; 425 426 // If set this fragment would like its instance retained across 427 // configuration changes. 428 boolean mRetainInstance; 429 430 // If set this fragment is being retained across the current config change. 431 boolean mRetaining; 432 433 // If set this fragment has menu items to contribute. 434 boolean mHasMenu; 435 436 // Used to verify that subclasses call through to super class. 437 boolean mCalled; 438 439 // If app has requested a specific animation, this is the one to use. 440 int mNextAnim; 441 442 // The parent container of the fragment after dynamically added to UI. 443 ViewGroup mContainer; 444 445 // The View generated for this fragment. 446 View mView; 447 448 LoaderManagerImpl mLoaderManager; 449 boolean mLoadersStarted; 450 boolean mCheckedForLoaderManager; 451 452 /** 453 * Thrown by {@link Fragment#instantiate(Context, String, Bundle)} when 454 * there is an instantiation failure. 455 */ 456 static public class InstantiationException extends AndroidRuntimeException { 457 public InstantiationException(String msg, Exception cause) { 458 super(msg, cause); 459 } 460 } 461 462 /** 463 * Default constructor. <strong>Every</strong> fragment must have an 464 * empty constructor, so it can be instantiated when restoring its 465 * activity's state. It is strongly recommended that subclasses do not 466 * have other constructors with parameters, since these constructors 467 * will not be called when the fragment is re-instantiated; instead, 468 * arguments can be supplied by the caller with {@link #setArguments} 469 * and later retrieved by the Fragment with {@link #getArguments}. 470 * 471 * <p>Applications should generally not implement a constructor. The 472 * first place application code an run where the fragment is ready to 473 * be used is in {@link #onAttach(Activity)}, the point where the fragment 474 * is actually associated with its activity. Some applications may also 475 * want to implement {@link #onInflate} to retrieve attributes from a 476 * layout resource, though should take care here because this happens for 477 * the fragment is attached to its activity. 478 */ 479 public Fragment() { 480 } 481 482 /** 483 * Like {@link #instantiate(Context, String, Bundle)} but with a null 484 * argument Bundle. 485 */ 486 public static Fragment instantiate(Context context, String fname) { 487 return instantiate(context, fname, null); 488 } 489 490 /** 491 * Create a new instance of a Fragment with the given class name. This is 492 * the same as calling its empty constructor. 493 * 494 * @param context The calling context being used to instantiate the fragment. 495 * This is currently just used to get its ClassLoader. 496 * @param fname The class name of the fragment to instantiate. 497 * @param args Bundle of arguments to supply to the fragment, which it 498 * can retrieve with {@link #getArguments()}. May be null. 499 * @return Returns a new fragment instance. 500 * @throws InstantiationException If there is a failure in instantiating 501 * the given fragment class. This is a runtime exception; it is not 502 * normally expected to happen. 503 */ 504 public static Fragment instantiate(Context context, String fname, Bundle args) { 505 try { 506 Class<?> clazz = sClassMap.get(fname); 507 if (clazz == null) { 508 // Class not found in the cache, see if it's real, and try to add it 509 clazz = context.getClassLoader().loadClass(fname); 510 sClassMap.put(fname, clazz); 511 } 512 Fragment f = (Fragment)clazz.newInstance(); 513 if (args != null) { 514 args.setClassLoader(f.getClass().getClassLoader()); 515 f.mArguments = args; 516 } 517 return f; 518 } catch (ClassNotFoundException e) { 519 throw new InstantiationException("Unable to instantiate fragment " + fname 520 + ": make sure class name exists, is public, and has an" 521 + " empty constructor that is public", e); 522 } catch (java.lang.InstantiationException e) { 523 throw new InstantiationException("Unable to instantiate fragment " + fname 524 + ": make sure class name exists, is public, and has an" 525 + " empty constructor that is public", e); 526 } catch (IllegalAccessException e) { 527 throw new InstantiationException("Unable to instantiate fragment " + fname 528 + ": make sure class name exists, is public, and has an" 529 + " empty constructor that is public", e); 530 } 531 } 532 533 final void restoreViewState() { 534 if (mSavedViewState != null) { 535 mView.restoreHierarchyState(mSavedViewState); 536 mSavedViewState = null; 537 } 538 } 539 540 final void setIndex(int index) { 541 mIndex = index; 542 mWho = "android:fragment:" + mIndex; 543 } 544 545 final void clearIndex() { 546 mIndex = -1; 547 mWho = null; 548 } 549 550 final boolean isInBackStack() { 551 return mBackStackNesting > 0; 552 } 553 554 /** 555 * Subclasses can not override equals(). 556 */ 557 @Override final public boolean equals(Object o) { 558 return super.equals(o); 559 } 560 561 /** 562 * Subclasses can not override hashCode(). 563 */ 564 @Override final public int hashCode() { 565 return super.hashCode(); 566 } 567 568 @Override 569 public String toString() { 570 StringBuilder sb = new StringBuilder(128); 571 DebugUtils.buildShortClassTag(this, sb); 572 if (mIndex >= 0) { 573 sb.append(" #"); 574 sb.append(mIndex); 575 } 576 if (mFragmentId != 0) { 577 sb.append(" id=0x"); 578 sb.append(Integer.toHexString(mFragmentId)); 579 } 580 if (mTag != null) { 581 sb.append(" "); 582 sb.append(mTag); 583 } 584 sb.append('}'); 585 return sb.toString(); 586 } 587 588 /** 589 * Return the identifier this fragment is known by. This is either 590 * the android:id value supplied in a layout or the container view ID 591 * supplied when adding the fragment. 592 */ 593 final public int getId() { 594 return mFragmentId; 595 } 596 597 /** 598 * Get the tag name of the fragment, if specified. 599 */ 600 final public String getTag() { 601 return mTag; 602 } 603 604 /** 605 * Supply the construction arguments for this fragment. This can only 606 * be called before the fragment has been attached to its activity; that 607 * is, you should call it immediately after constructing the fragment. The 608 * arguments supplied here will be retained across fragment destroy and 609 * creation. 610 */ 611 public void setArguments(Bundle args) { 612 if (mIndex >= 0) { 613 throw new IllegalStateException("Fragment already active"); 614 } 615 mArguments = args; 616 } 617 618 /** 619 * Return the arguments supplied when the fragment was instantiated, 620 * if any. 621 */ 622 final public Bundle getArguments() { 623 return mArguments; 624 } 625 626 /** 627 * Optional target for this fragment. This may be used, for example, 628 * if this fragment is being started by another, and when done wants to 629 * give a result back to the first. The target set here is retained 630 * across instances via {@link FragmentManager#putFragment 631 * FragmentManager.putFragment()}. 632 * 633 * @param fragment The fragment that is the target of this one. 634 * @param requestCode Optional request code, for convenience if you 635 * are going to call back with {@link #onActivityResult(int, int, Intent)}. 636 */ 637 public void setTargetFragment(Fragment fragment, int requestCode) { 638 mTarget = fragment; 639 mTargetRequestCode = requestCode; 640 } 641 642 /** 643 * Return the target fragment set by {@link #setTargetFragment}. 644 */ 645 final public Fragment getTargetFragment() { 646 return mTarget; 647 } 648 649 /** 650 * Return the target request code set by {@link #setTargetFragment}. 651 */ 652 final public int getTargetRequestCode() { 653 return mTargetRequestCode; 654 } 655 656 /** 657 * Return the Activity this fragment is currently associated with. 658 */ 659 final public Activity getActivity() { 660 return mActivity; 661 } 662 663 /** 664 * Return <code>getActivity().getResources()</code>. 665 */ 666 final public Resources getResources() { 667 if (mActivity == null) { 668 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 669 } 670 return mActivity.getResources(); 671 } 672 673 /** 674 * Return a localized, styled CharSequence from the application's package's 675 * default string table. 676 * 677 * @param resId Resource id for the CharSequence text 678 */ 679 public final CharSequence getText(int resId) { 680 return getResources().getText(resId); 681 } 682 683 /** 684 * Return a localized string from the application's package's 685 * default string table. 686 * 687 * @param resId Resource id for the string 688 */ 689 public final String getString(int resId) { 690 return getResources().getString(resId); 691 } 692 693 /** 694 * Return a localized formatted string from the application's package's 695 * default string table, substituting the format arguments as defined in 696 * {@link java.util.Formatter} and {@link java.lang.String#format}. 697 * 698 * @param resId Resource id for the format string 699 * @param formatArgs The format arguments that will be used for substitution. 700 */ 701 702 public final String getString(int resId, Object... formatArgs) { 703 return getResources().getString(resId, formatArgs); 704 } 705 706 /** 707 * Return the FragmentManager for interacting with fragments associated 708 * with this fragment's activity. Note that this will be non-null slightly 709 * before {@link #getActivity()}, during the time from when the fragment is 710 * placed in a {@link FragmentTransaction} until it is committed and 711 * attached to its activity. 712 */ 713 final public FragmentManager getFragmentManager() { 714 return mFragmentManager; 715 } 716 717 /** 718 * Return true if the fragment is currently added to its activity. 719 */ 720 final public boolean isAdded() { 721 return mActivity != null && mAdded; 722 } 723 724 /** 725 * Return true if this fragment is currently being removed from its 726 * activity. This is <em>not</em> whether its activity is finishing, but 727 * rather whether it is in the process of being removed from its activity. 728 */ 729 final public boolean isRemoving() { 730 return mRemoving; 731 } 732 733 /** 734 * Return true if the layout is included as part of an activity view 735 * hierarchy via the <fragment> tag. This will always be true when 736 * fragments are created through the <fragment> tag, <em>except</em> 737 * in the case where an old fragment is restored from a previous state and 738 * it does not appear in the layout of the current state. 739 */ 740 final public boolean isInLayout() { 741 return mInLayout; 742 } 743 744 /** 745 * Return true if the fragment is in the resumed state. This is true 746 * for the duration of {@link #onResume()} and {@link #onPause()} as well. 747 */ 748 final public boolean isResumed() { 749 return mResumed; 750 } 751 752 /** 753 * Return true if the fragment is currently visible to the user. This means 754 * it: (1) has been added, (2) has its view attached to the window, and 755 * (3) is not hidden. 756 */ 757 final public boolean isVisible() { 758 return isAdded() && !isHidden() && mView != null 759 && mView.getWindowToken() != null && mView.getVisibility() == View.VISIBLE; 760 } 761 762 /** 763 * Return true if the fragment has been hidden. By default fragments 764 * are shown. You can find out about changes to this state with 765 * {@link #onHiddenChanged}. Note that the hidden state is orthogonal 766 * to other states -- that is, to be visible to the user, a fragment 767 * must be both started and not hidden. 768 */ 769 final public boolean isHidden() { 770 return mHidden; 771 } 772 773 /** 774 * Called when the hidden state (as returned by {@link #isHidden()} of 775 * the fragment has changed. Fragments start out not hidden; this will 776 * be called whenever the fragment changes state from that. 777 * @param hidden True if the fragment is now hidden, false if it is not 778 * visible. 779 */ 780 public void onHiddenChanged(boolean hidden) { 781 } 782 783 /** 784 * Control whether a fragment instance is retained across Activity 785 * re-creation (such as from a configuration change). This can only 786 * be used with fragments not in the back stack. If set, the fragment 787 * lifecycle will be slightly different when an activity is recreated: 788 * <ul> 789 * <li> {@link #onDestroy()} will not be called (but {@link #onDetach()} still 790 * will be, because the fragment is being detached from its current activity). 791 * <li> {@link #onCreate(Bundle)} will not be called since the fragment 792 * is not being re-created. 793 * <li> {@link #onAttach(Activity)} and {@link #onActivityCreated(Bundle)} <b>will</b> 794 * still be called. 795 * </ul> 796 */ 797 public void setRetainInstance(boolean retain) { 798 mRetainInstance = retain; 799 } 800 801 final public boolean getRetainInstance() { 802 return mRetainInstance; 803 } 804 805 /** 806 * Report that this fragment would like to participate in populating 807 * the options menu by receiving a call to {@link #onCreateOptionsMenu} 808 * and related methods. 809 * 810 * @param hasMenu If true, the fragment has menu items to contribute. 811 */ 812 public void setHasOptionsMenu(boolean hasMenu) { 813 if (mHasMenu != hasMenu) { 814 mHasMenu = hasMenu; 815 if (isAdded() && !isHidden()) { 816 mActivity.invalidateOptionsMenu(); 817 } 818 } 819 } 820 821 /** 822 * Return the LoaderManager for this fragment, creating it if needed. 823 */ 824 public LoaderManager getLoaderManager() { 825 if (mLoaderManager != null) { 826 return mLoaderManager; 827 } 828 if (mActivity == null) { 829 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 830 } 831 mCheckedForLoaderManager = true; 832 mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, true); 833 return mLoaderManager; 834 } 835 836 /** 837 * Call {@link Activity#startActivity(Intent)} on the fragment's 838 * containing Activity. 839 */ 840 public void startActivity(Intent intent) { 841 if (mActivity == null) { 842 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 843 } 844 mActivity.startActivityFromFragment(this, intent, -1); 845 } 846 847 /** 848 * Call {@link Activity#startActivityForResult(Intent, int)} on the fragment's 849 * containing Activity. 850 */ 851 public void startActivityForResult(Intent intent, int requestCode) { 852 if (mActivity == null) { 853 throw new IllegalStateException("Fragment " + this + " not attached to Activity"); 854 } 855 mActivity.startActivityFromFragment(this, intent, requestCode); 856 } 857 858 /** 859 * Receive the result from a previous call to 860 * {@link #startActivityForResult(Intent, int)}. This follows the 861 * related Activity API as described there in 862 * {@link Activity#onActivityResult(int, int, Intent)}. 863 * 864 * @param requestCode The integer request code originally supplied to 865 * startActivityForResult(), allowing you to identify who this 866 * result came from. 867 * @param resultCode The integer result code returned by the child activity 868 * through its setResult(). 869 * @param data An Intent, which can return result data to the caller 870 * (various data can be attached to Intent "extras"). 871 */ 872 public void onActivityResult(int requestCode, int resultCode, Intent data) { 873 } 874 875 /** 876 * @hide Hack so that DialogFragment can make its Dialog before creating 877 * its views, and the view construction can use the dialog's context for 878 * inflation. Maybe this should become a public API. Note sure. 879 */ 880 public LayoutInflater getLayoutInflater(Bundle savedInstanceState) { 881 return mActivity.getLayoutInflater(); 882 } 883 884 /** 885 * @deprecated Use {@link #onInflate(Activity, AttributeSet, Bundle)} instead. 886 */ 887 @Deprecated 888 public void onInflate(AttributeSet attrs, Bundle savedInstanceState) { 889 mCalled = true; 890 } 891 892 /** 893 * Called when a fragment is being created as part of a view layout 894 * inflation, typically from setting the content view of an activity. This 895 * may be called immediately after the fragment is created from a <fragment> 896 * tag in a layout file. Note this is <em>before</em> the fragment's 897 * {@link #onAttach(Activity)} has been called; all you should do here is 898 * parse the attributes and save them away. 899 * 900 * <p>This is called every time the fragment is inflated, even if it is 901 * being inflated into a new instance with saved state. It typically makes 902 * sense to re-parse the parameters each time, to allow them to change with 903 * different configurations.</p> 904 * 905 * <p>Here is a typical implementation of a fragment that can take parameters 906 * both through attributes supplied here as well from {@link #getArguments()}:</p> 907 * 908 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java 909 * fragment} 910 * 911 * <p>Note that parsing the XML attributes uses a "styleable" resource. The 912 * declaration for the styleable used here is:</p> 913 * 914 * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments} 915 * 916 * <p>The fragment can then be declared within its activity's content layout 917 * through a tag like this:</p> 918 * 919 * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes} 920 * 921 * <p>This fragment can also be created dynamically from arguments given 922 * at runtime in the arguments Bundle; here is an example of doing so at 923 * creation of the containing activity:</p> 924 * 925 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java 926 * create} 927 * 928 * @param activity The Activity that is inflating this fragment. 929 * @param attrs The attributes at the tag where the fragment is 930 * being created. 931 * @param savedInstanceState If the fragment is being re-created from 932 * a previous saved state, this is the state. 933 */ 934 public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { 935 onInflate(attrs, savedInstanceState); 936 mCalled = true; 937 } 938 939 /** 940 * Called when a fragment is first attached to its activity. 941 * {@link #onCreate(Bundle)} will be called after this. 942 */ 943 public void onAttach(Activity activity) { 944 mCalled = true; 945 } 946 947 /** 948 * Called when a fragment loads an animation. 949 */ 950 public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { 951 return null; 952 } 953 954 /** 955 * Called to do initial creation of a fragment. This is called after 956 * {@link #onAttach(Activity)} and before 957 * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 958 * 959 * <p>Note that this can be called while the fragment's activity is 960 * still in the process of being created. As such, you can not rely 961 * on things like the activity's content view hierarchy being initialized 962 * at this point. If you want to do work once the activity itself is 963 * created, see {@link #onActivityCreated(Bundle)}. 964 * 965 * @param savedInstanceState If the fragment is being re-created from 966 * a previous saved state, this is the state. 967 */ 968 public void onCreate(Bundle savedInstanceState) { 969 mCalled = true; 970 } 971 972 /** 973 * Called immediately after {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)} 974 * has returned, but before any saved state has been restored in to the view. 975 * This gives subclasses a chance to initialize themselves once 976 * they know their view hierarchy has been completely created. The fragment's 977 * view hierarchy is not however attached to its parent at this point. 978 * @param view The View returned by {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}. 979 * @param savedInstanceState If non-null, this fragment is being re-constructed 980 * from a previous saved state as given here. 981 */ 982 public void onViewCreated(View view, Bundle savedInstanceState) { 983 } 984 985 /** 986 * Called to have the fragment instantiate its user interface view. 987 * This is optional, and non-graphical fragments can return null (which 988 * is the default implementation). This will be called between 989 * {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}. 990 * 991 * <p>If you return a View from here, you will later be called in 992 * {@link #onDestroyView} when the view is being released. 993 * 994 * @param inflater The LayoutInflater object that can be used to inflate 995 * any views in the fragment, 996 * @param container If non-null, this is the parent view that the fragment's 997 * UI should be attached to. The fragment should not add the view itself, 998 * but this can be used to generate the LayoutParams of the view. 999 * @param savedInstanceState If non-null, this fragment is being re-constructed 1000 * from a previous saved state as given here. 1001 * 1002 * @return Return the View for the fragment's UI, or null. 1003 */ 1004 public View onCreateView(LayoutInflater inflater, ViewGroup container, 1005 Bundle savedInstanceState) { 1006 return null; 1007 } 1008 1009 /** 1010 * Get the root view for the fragment's layout (the one returned by {@link #onCreateView}), 1011 * if provided. 1012 * 1013 * @return The fragment's root view, or null if it has no layout. 1014 */ 1015 public View getView() { 1016 return mView; 1017 } 1018 1019 /** 1020 * Called when the fragment's activity has been created and this 1021 * fragment's view hierarchy instantiated. It can be used to do final 1022 * initialization once these pieces are in place, such as retrieving 1023 * views or restoring state. It is also useful for fragments that use 1024 * {@link #setRetainInstance(boolean)} to retain their instance, 1025 * as this callback tells the fragment when it is fully associated with 1026 * the new activity instance. This is called after {@link #onCreateView} 1027 * and before {@link #onStart()}. 1028 * 1029 * @param savedInstanceState If the fragment is being re-created from 1030 * a previous saved state, this is the state. 1031 */ 1032 public void onActivityCreated(Bundle savedInstanceState) { 1033 mCalled = true; 1034 } 1035 1036 /** 1037 * Called when the Fragment is visible to the user. This is generally 1038 * tied to {@link Activity#onStart() Activity.onStart} of the containing 1039 * Activity's lifecycle. 1040 */ 1041 public void onStart() { 1042 mCalled = true; 1043 1044 if (!mLoadersStarted) { 1045 mLoadersStarted = true; 1046 if (!mCheckedForLoaderManager) { 1047 mCheckedForLoaderManager = true; 1048 mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false); 1049 } 1050 if (mLoaderManager != null) { 1051 mLoaderManager.doStart(); 1052 } 1053 } 1054 } 1055 1056 /** 1057 * Called when the fragment is visible to the user and actively running. 1058 * This is generally 1059 * tied to {@link Activity#onResume() Activity.onResume} of the containing 1060 * Activity's lifecycle. 1061 */ 1062 public void onResume() { 1063 mCalled = true; 1064 } 1065 1066 /** 1067 * Called to ask the fragment to save its current dynamic state, so it 1068 * can later be reconstructed in a new instance of its process is 1069 * restarted. If a new instance of the fragment later needs to be 1070 * created, the data you place in the Bundle here will be available 1071 * in the Bundle given to {@link #onCreate(Bundle)}, 1072 * {@link #onCreateView(LayoutInflater, ViewGroup, Bundle)}, and 1073 * {@link #onActivityCreated(Bundle)}. 1074 * 1075 * <p>This corresponds to {@link Activity#onSaveInstanceState(Bundle) 1076 * Activity.onSaveInstanceState(Bundle)} and most of the discussion there 1077 * applies here as well. Note however: <em>this method may be called 1078 * at any time before {@link #onDestroy()}</em>. There are many situations 1079 * where a fragment may be mostly torn down (such as when placed on the 1080 * back stack with no UI showing), but its state will not be saved until 1081 * its owning activity actually needs to save its state. 1082 * 1083 * @param outState Bundle in which to place your saved state. 1084 */ 1085 public void onSaveInstanceState(Bundle outState) { 1086 } 1087 1088 public void onConfigurationChanged(Configuration newConfig) { 1089 mCalled = true; 1090 } 1091 1092 /** 1093 * Called when the Fragment is no longer resumed. This is generally 1094 * tied to {@link Activity#onPause() Activity.onPause} of the containing 1095 * Activity's lifecycle. 1096 */ 1097 public void onPause() { 1098 mCalled = true; 1099 } 1100 1101 /** 1102 * Called when the Fragment is no longer started. This is generally 1103 * tied to {@link Activity#onStop() Activity.onStop} of the containing 1104 * Activity's lifecycle. 1105 */ 1106 public void onStop() { 1107 mCalled = true; 1108 } 1109 1110 public void onLowMemory() { 1111 mCalled = true; 1112 } 1113 1114 /** 1115 * Called when the view previously created by {@link #onCreateView} has 1116 * been detached from the fragment. The next time the fragment needs 1117 * to be displayed, a new view will be created. This is called 1118 * after {@link #onStop()} and before {@link #onDestroy()}. It is called 1119 * <em>regardless</em> of whether {@link #onCreateView} returned a 1120 * non-null view. Internally it is called after the view's state has 1121 * been saved but before it has been removed from its parent. 1122 */ 1123 public void onDestroyView() { 1124 mCalled = true; 1125 } 1126 1127 /** 1128 * Called when the fragment is no longer in use. This is called 1129 * after {@link #onStop()} and before {@link #onDetach()}. 1130 */ 1131 public void onDestroy() { 1132 mCalled = true; 1133 //Log.v("foo", "onDestroy: mCheckedForLoaderManager=" + mCheckedForLoaderManager 1134 // + " mLoaderManager=" + mLoaderManager); 1135 if (!mCheckedForLoaderManager) { 1136 mCheckedForLoaderManager = true; 1137 mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false); 1138 } 1139 if (mLoaderManager != null) { 1140 mLoaderManager.doDestroy(); 1141 } 1142 } 1143 1144 /** 1145 * Called when the fragment is no longer attached to its activity. This 1146 * is called after {@link #onDestroy()}. 1147 */ 1148 public void onDetach() { 1149 mCalled = true; 1150 } 1151 1152 /** 1153 * Initialize the contents of the Activity's standard options menu. You 1154 * should place your menu items in to <var>menu</var>. For this method 1155 * to be called, you must have first called {@link #setHasOptionsMenu}. See 1156 * {@link Activity#onCreateOptionsMenu(Menu) Activity.onCreateOptionsMenu} 1157 * for more information. 1158 * 1159 * @param menu The options menu in which you place your items. 1160 * 1161 * @see #setHasOptionsMenu 1162 * @see #onPrepareOptionsMenu 1163 * @see #onOptionsItemSelected 1164 */ 1165 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 1166 } 1167 1168 /** 1169 * Prepare the Screen's standard options menu to be displayed. This is 1170 * called right before the menu is shown, every time it is shown. You can 1171 * use this method to efficiently enable/disable items or otherwise 1172 * dynamically modify the contents. See 1173 * {@link Activity#onPrepareOptionsMenu(Menu) Activity.onPrepareOptionsMenu} 1174 * for more information. 1175 * 1176 * @param menu The options menu as last shown or first initialized by 1177 * onCreateOptionsMenu(). 1178 * 1179 * @see #setHasOptionsMenu 1180 * @see #onCreateOptionsMenu 1181 */ 1182 public void onPrepareOptionsMenu(Menu menu) { 1183 } 1184 1185 /** 1186 * Called when this fragment's option menu items are no longer being 1187 * included in the overall options menu. Receiving this call means that 1188 * the menu needed to be rebuilt, but this fragment's items were not 1189 * included in the newly built menu (its {@link #onCreateOptionsMenu(Menu, MenuInflater)} 1190 * was not called). 1191 */ 1192 public void onDestroyOptionsMenu() { 1193 } 1194 1195 /** 1196 * This hook is called whenever an item in your options menu is selected. 1197 * The default implementation simply returns false to have the normal 1198 * processing happen (calling the item's Runnable or sending a message to 1199 * its Handler as appropriate). You can use this method for any items 1200 * for which you would like to do processing without those other 1201 * facilities. 1202 * 1203 * <p>Derived classes should call through to the base class for it to 1204 * perform the default menu handling. 1205 * 1206 * @param item The menu item that was selected. 1207 * 1208 * @return boolean Return false to allow normal menu processing to 1209 * proceed, true to consume it here. 1210 * 1211 * @see #onCreateOptionsMenu 1212 */ 1213 public boolean onOptionsItemSelected(MenuItem item) { 1214 return false; 1215 } 1216 1217 /** 1218 * This hook is called whenever the options menu is being closed (either by the user canceling 1219 * the menu with the back/menu button, or when an item is selected). 1220 * 1221 * @param menu The options menu as last shown or first initialized by 1222 * onCreateOptionsMenu(). 1223 */ 1224 public void onOptionsMenuClosed(Menu menu) { 1225 } 1226 1227 /** 1228 * Called when a context menu for the {@code view} is about to be shown. 1229 * Unlike {@link #onCreateOptionsMenu}, this will be called every 1230 * time the context menu is about to be shown and should be populated for 1231 * the view (or item inside the view for {@link AdapterView} subclasses, 1232 * this can be found in the {@code menuInfo})). 1233 * <p> 1234 * Use {@link #onContextItemSelected(android.view.MenuItem)} to know when an 1235 * item has been selected. 1236 * <p> 1237 * The default implementation calls up to 1238 * {@link Activity#onCreateContextMenu Activity.onCreateContextMenu}, though 1239 * you can not call this implementation if you don't want that behavior. 1240 * <p> 1241 * It is not safe to hold onto the context menu after this method returns. 1242 * {@inheritDoc} 1243 */ 1244 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { 1245 getActivity().onCreateContextMenu(menu, v, menuInfo); 1246 } 1247 1248 /** 1249 * Registers a context menu to be shown for the given view (multiple views 1250 * can show the context menu). This method will set the 1251 * {@link OnCreateContextMenuListener} on the view to this fragment, so 1252 * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} will be 1253 * called when it is time to show the context menu. 1254 * 1255 * @see #unregisterForContextMenu(View) 1256 * @param view The view that should show a context menu. 1257 */ 1258 public void registerForContextMenu(View view) { 1259 view.setOnCreateContextMenuListener(this); 1260 } 1261 1262 /** 1263 * Prevents a context menu to be shown for the given view. This method will 1264 * remove the {@link OnCreateContextMenuListener} on the view. 1265 * 1266 * @see #registerForContextMenu(View) 1267 * @param view The view that should stop showing a context menu. 1268 */ 1269 public void unregisterForContextMenu(View view) { 1270 view.setOnCreateContextMenuListener(null); 1271 } 1272 1273 /** 1274 * This hook is called whenever an item in a context menu is selected. The 1275 * default implementation simply returns false to have the normal processing 1276 * happen (calling the item's Runnable or sending a message to its Handler 1277 * as appropriate). You can use this method for any items for which you 1278 * would like to do processing without those other facilities. 1279 * <p> 1280 * Use {@link MenuItem#getMenuInfo()} to get extra information set by the 1281 * View that added this menu item. 1282 * <p> 1283 * Derived classes should call through to the base class for it to perform 1284 * the default menu handling. 1285 * 1286 * @param item The context menu item that was selected. 1287 * @return boolean Return false to allow normal context menu processing to 1288 * proceed, true to consume it here. 1289 */ 1290 public boolean onContextItemSelected(MenuItem item) { 1291 return false; 1292 } 1293 1294 /** 1295 * Print the Fragments's state into the given stream. 1296 * 1297 * @param prefix Text to print at the front of each line. 1298 * @param fd The raw file descriptor that the dump is being sent to. 1299 * @param writer The PrintWriter to which you should dump your state. This will be 1300 * closed for you after you return. 1301 * @param args additional arguments to the dump request. 1302 */ 1303 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 1304 writer.print(prefix); writer.print("mFragmentId=#"); 1305 writer.print(Integer.toHexString(mFragmentId)); 1306 writer.print(" mContainerId#="); 1307 writer.print(Integer.toHexString(mContainerId)); 1308 writer.print(" mTag="); writer.println(mTag); 1309 writer.print(prefix); writer.print("mState="); writer.print(mState); 1310 writer.print(" mIndex="); writer.print(mIndex); 1311 writer.print(" mWho="); writer.print(mWho); 1312 writer.print(" mBackStackNesting="); writer.println(mBackStackNesting); 1313 writer.print(prefix); writer.print("mAdded="); writer.print(mAdded); 1314 writer.print(" mRemoving="); writer.print(mRemoving); 1315 writer.print(" mResumed="); writer.print(mResumed); 1316 writer.print(" mFromLayout="); writer.print(mFromLayout); 1317 writer.print(" mInLayout="); writer.println(mInLayout); 1318 writer.print(prefix); writer.print("mHidden="); writer.print(mHidden); 1319 writer.print(" mDetached="); writer.print(mDetached); 1320 writer.print(" mRetainInstance="); writer.print(mRetainInstance); 1321 writer.print(" mRetaining="); writer.print(mRetaining); 1322 writer.print(" mHasMenu="); writer.println(mHasMenu); 1323 if (mFragmentManager != null) { 1324 writer.print(prefix); writer.print("mFragmentManager="); 1325 writer.println(mFragmentManager); 1326 } 1327 if (mImmediateActivity != null) { 1328 writer.print(prefix); writer.print("mImmediateActivity="); 1329 writer.println(mImmediateActivity); 1330 } 1331 if (mActivity != null) { 1332 writer.print(prefix); writer.print("mActivity="); 1333 writer.println(mActivity); 1334 } 1335 if (mArguments != null) { 1336 writer.print(prefix); writer.print("mArguments="); writer.println(mArguments); 1337 } 1338 if (mSavedFragmentState != null) { 1339 writer.print(prefix); writer.print("mSavedFragmentState="); 1340 writer.println(mSavedFragmentState); 1341 } 1342 if (mSavedViewState != null) { 1343 writer.print(prefix); writer.print("mSavedViewState="); 1344 writer.println(mSavedViewState); 1345 } 1346 if (mTarget != null) { 1347 writer.print(prefix); writer.print("mTarget="); writer.print(mTarget); 1348 writer.print(" mTargetRequestCode="); 1349 writer.println(mTargetRequestCode); 1350 } 1351 if (mNextAnim != 0) { 1352 writer.print(prefix); writer.print("mNextAnim="); writer.println(mNextAnim); 1353 } 1354 if (mContainer != null) { 1355 writer.print(prefix); writer.print("mContainer="); writer.println(mContainer); 1356 } 1357 if (mView != null) { 1358 writer.print(prefix); writer.print("mView="); writer.println(mView); 1359 } 1360 if (mAnimatingAway != null) { 1361 writer.print(prefix); writer.print("mAnimatingAway="); writer.println(mAnimatingAway); 1362 writer.print(prefix); writer.print("mStateAfterAnimating="); 1363 writer.println(mStateAfterAnimating); 1364 } 1365 if (mLoaderManager != null) { 1366 writer.print(prefix); writer.println("Loader Manager:"); 1367 mLoaderManager.dump(prefix + " ", fd, writer, args); 1368 } 1369 } 1370 1371 void performStop() { 1372 onStop(); 1373 1374 if (mLoadersStarted) { 1375 mLoadersStarted = false; 1376 if (!mCheckedForLoaderManager) { 1377 mCheckedForLoaderManager = true; 1378 mLoaderManager = mActivity.getLoaderManager(mIndex, mLoadersStarted, false); 1379 } 1380 if (mLoaderManager != null) { 1381 if (mActivity == null || !mActivity.mChangingConfigurations) { 1382 mLoaderManager.doStop(); 1383 } else { 1384 mLoaderManager.doRetain(); 1385 } 1386 } 1387 } 1388 } 1389} 1390