FragmentActivity.java revision 4a7e12af4ec095c3a53bb8481d8d92f63157c3b7
1/* 2 * Copyright (C) 2011 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.support.v4.app; 18 19import android.app.Activity; 20import android.content.Context; 21import android.content.Intent; 22import android.content.res.Configuration; 23import android.content.res.TypedArray; 24import android.os.Bundle; 25import android.os.Handler; 26import android.os.Message; 27import android.os.Parcelable; 28import android.util.AttributeSet; 29import android.util.Log; 30import android.view.KeyEvent; 31import android.view.Menu; 32import android.view.MenuItem; 33import android.view.View; 34import android.view.Window; 35 36import java.io.FileDescriptor; 37import java.io.PrintWriter; 38import java.util.ArrayList; 39import java.util.HashMap; 40 41/** 42 * Base class for activities that want to use the support-based 43 * {@link android.support.v4.app.Fragment} and 44 * {@link android.support.v4.content.Loader} APIs. 45 * 46 * <p>When using this class as opposed to new platform's built-in fragment 47 * and loader support, you must use the {@link #getSupportFragmentManager()} 48 * and {@link #getSupportLoaderManager()} methods respectively to access 49 * those features. 50 * 51 * <p>Known limitations:</p> 52 * <ul> 53 * <li> <p>When using the <fragment> tag, this implementation can not 54 * use the parent view's ID as the new fragment's ID. You must explicitly 55 * specify an ID (or tag) in the <fragment>.</p> 56 * <li> <p>Prior to Honeycomb (3.0), an activity's state was saved before pausing. 57 * Fragments are a significant amount of new state, and dynamic enough that one 58 * often wants them to change between pausing and stopping. These classes 59 * throw an exception if you try to change the fragment state after it has been 60 * saved, to avoid accidental loss of UI state. However this is too restrictive 61 * prior to Honeycomb, where the state is saved before pausing. To address this, 62 * when running on platforms prior to Honeycomb an exception will not be thrown 63 * if you change fragments between the state save and the activity being stopped. 64 * This means that in some cases if the activity is restored from its last saved 65 * state, this may be a snapshot slightly before what the user last saw.</p> 66 * </ul> 67 */ 68public class FragmentActivity extends Activity { 69 private static final String TAG = "FragmentActivity"; 70 71 private static final String FRAGMENTS_TAG = "android:support:fragments"; 72 73 // This is the SDK API version of Honeycomb (3.0). 74 private static final int HONEYCOMB = 11; 75 76 static final int MSG_REALLY_STOPPED = 1; 77 static final int MSG_RESUME_PENDING = 2; 78 79 final Handler mHandler = new Handler() { 80 @Override 81 public void handleMessage(Message msg) { 82 switch (msg.what) { 83 case MSG_REALLY_STOPPED: 84 if (mStopped) { 85 doReallyStop(false); 86 } 87 break; 88 case MSG_RESUME_PENDING: 89 mFragments.dispatchResume(); 90 mFragments.execPendingActions(); 91 break; 92 default: 93 super.handleMessage(msg); 94 } 95 } 96 97 }; 98 final FragmentManagerImpl mFragments = new FragmentManagerImpl(); 99 100 boolean mCreated; 101 boolean mResumed; 102 boolean mStopped; 103 boolean mReallyStopped; 104 boolean mRetaining; 105 106 boolean mOptionsMenuInvalidated; 107 108 boolean mCheckedForLoaderManager; 109 boolean mLoadersStarted; 110 HCSparseArray<LoaderManagerImpl> mAllLoaderManagers; 111 LoaderManagerImpl mLoaderManager; 112 113 static final class NonConfigurationInstances { 114 Object activity; 115 Object custom; 116 HashMap<String, Object> children; 117 ArrayList<Fragment> fragments; 118 HCSparseArray<LoaderManagerImpl> loaders; 119 } 120 121 static class FragmentTag { 122 public static final int[] Fragment = { 123 0x01010003, 0x010100d0, 0x010100d1 124 }; 125 public static final int Fragment_id = 1; 126 public static final int Fragment_name = 0; 127 public static final int Fragment_tag = 2; 128 } 129 130 // ------------------------------------------------------------------------ 131 // HOOKS INTO ACTIVITY 132 // ------------------------------------------------------------------------ 133 134 /** 135 * Dispatch incoming result to the correct fragment. 136 */ 137 @Override 138 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 139 int index = requestCode>>16; 140 if (index != 0) { 141 index--; 142 if (mFragments.mActive == null || index < 0 || index >= mFragments.mActive.size()) { 143 Log.w(TAG, "Activity result fragment index out of range: 0x" 144 + Integer.toHexString(requestCode)); 145 return; 146 } 147 Fragment frag = mFragments.mActive.get(index); 148 if (frag == null) { 149 Log.w(TAG, "Activity result no fragment exists for index: 0x" 150 + Integer.toHexString(requestCode)); 151 } else { 152 frag.onActivityResult(requestCode&0xffff, resultCode, data); 153 } 154 return; 155 } 156 157 super.onActivityResult(requestCode, resultCode, data); 158 } 159 160 /** 161 * Take care of popping the fragment back stack or finishing the activity 162 * as appropriate. 163 */ 164 public void onBackPressed() { 165 if (!mFragments.popBackStackImmediate()) { 166 finish(); 167 } 168 } 169 170 /** 171 * Dispatch configuration change to all fragments. 172 */ 173 @Override 174 public void onConfigurationChanged(Configuration newConfig) { 175 super.onConfigurationChanged(newConfig); 176 mFragments.dispatchConfigurationChanged(newConfig); 177 } 178 179 /** 180 * Perform initialization of all fragments and loaders. 181 */ 182 @Override 183 protected void onCreate(Bundle savedInstanceState) { 184 mFragments.attachActivity(this); 185 // Old versions of the platform didn't do this! 186 if (getLayoutInflater().getFactory() == null) { 187 getLayoutInflater().setFactory(this); 188 } 189 190 super.onCreate(savedInstanceState); 191 192 NonConfigurationInstances nc = (NonConfigurationInstances) 193 getLastNonConfigurationInstance(); 194 if (nc != null) { 195 mAllLoaderManagers = nc.loaders; 196 } 197 if (savedInstanceState != null) { 198 Parcelable p = savedInstanceState.getParcelable(FRAGMENTS_TAG); 199 mFragments.restoreAllState(p, nc != null ? nc.fragments : null); 200 } 201 mFragments.dispatchCreate(); 202 } 203 204 /** 205 * Dispatch to Fragment.onCreateOptionsMenu(). 206 */ 207 @Override 208 public boolean onCreatePanelMenu(int featureId, Menu menu) { 209 if (featureId == Window.FEATURE_OPTIONS_PANEL) { 210 boolean show = super.onCreatePanelMenu(featureId, menu); 211 show |= mFragments.dispatchCreateOptionsMenu(menu, getMenuInflater()); 212 if (android.os.Build.VERSION.SDK_INT >= HONEYCOMB) { 213 return show; 214 } 215 // Prior to Honeycomb, the framework can't invalidate the options 216 // menu, so we must always say we have one in case the app later 217 // invalidates it and needs to have it shown. 218 return true; 219 } 220 return super.onCreatePanelMenu(featureId, menu); 221 } 222 223 /** 224 * Add support for inflating the <fragment> tag. 225 */ 226 @Override 227 public View onCreateView(String name, Context context, AttributeSet attrs) { 228 if (!"fragment".equals(name)) { 229 return super.onCreateView(name, context, attrs); 230 } 231 232 String fname = attrs.getAttributeValue(null, "class"); 233 TypedArray a = context.obtainStyledAttributes(attrs, FragmentTag.Fragment); 234 if (fname == null) { 235 fname = a.getString(FragmentTag.Fragment_name); 236 } 237 int id = a.getResourceId(FragmentTag.Fragment_id, View.NO_ID); 238 String tag = a.getString(FragmentTag.Fragment_tag); 239 a.recycle(); 240 241 View parent = null; // NOTE: no way to get parent pre-Honeycomb. 242 int containerId = parent != null ? parent.getId() : 0; 243 if (containerId == View.NO_ID && id == View.NO_ID && tag == null) { 244 throw new IllegalArgumentException(attrs.getPositionDescription() 245 + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname); 246 } 247 248 // If we restored from a previous state, we may already have 249 // instantiated this fragment from the state and should use 250 // that instance instead of making a new one. 251 Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null; 252 if (fragment == null && tag != null) { 253 fragment = mFragments.findFragmentByTag(tag); 254 } 255 if (fragment == null && containerId != View.NO_ID) { 256 fragment = mFragments.findFragmentById(containerId); 257 } 258 259 if (FragmentManagerImpl.DEBUG) Log.v(TAG, "onCreateView: id=0x" 260 + Integer.toHexString(id) + " fname=" + fname 261 + " existing=" + fragment); 262 if (fragment == null) { 263 fragment = Fragment.instantiate(this, fname); 264 fragment.mFromLayout = true; 265 fragment.mFragmentId = id != 0 ? id : containerId; 266 fragment.mContainerId = containerId; 267 fragment.mTag = tag; 268 fragment.mInLayout = true; 269 fragment.mFragmentManager = mFragments; 270 fragment.onInflate(this, attrs, fragment.mSavedFragmentState); 271 mFragments.addFragment(fragment, true); 272 273 } else if (fragment.mInLayout) { 274 // A fragment already exists and it is not one we restored from 275 // previous state. 276 throw new IllegalArgumentException(attrs.getPositionDescription() 277 + ": Duplicate id 0x" + Integer.toHexString(id) 278 + ", tag " + tag + ", or parent id 0x" + Integer.toHexString(containerId) 279 + " with another fragment for " + fname); 280 } else { 281 // This fragment was retained from a previous instance; get it 282 // going now. 283 fragment.mInLayout = true; 284 // If this fragment is newly instantiated (either right now, or 285 // from last saved state), then give it the attributes to 286 // initialize itself. 287 if (!fragment.mRetaining) { 288 fragment.onInflate(this, attrs, fragment.mSavedFragmentState); 289 } 290 mFragments.moveToState(fragment); 291 } 292 293 if (fragment.mView == null) { 294 throw new IllegalStateException("Fragment " + fname 295 + " did not create a view."); 296 } 297 if (id != 0) { 298 fragment.mView.setId(id); 299 } 300 if (fragment.mView.getTag() == null) { 301 fragment.mView.setTag(tag); 302 } 303 return fragment.mView; 304 } 305 306 /** 307 * Destroy all fragments and loaders. 308 */ 309 @Override 310 protected void onDestroy() { 311 super.onDestroy(); 312 313 doReallyStop(false); 314 315 mFragments.dispatchDestroy(); 316 if (mLoaderManager != null) { 317 mLoaderManager.doDestroy(); 318 } 319 } 320 321 /** 322 * Take care of calling onBackPressed() for pre-Eclair platforms. 323 */ 324 @Override 325 public boolean onKeyDown(int keyCode, KeyEvent event) { 326 if (android.os.Build.VERSION.SDK_INT < 5 /* ECLAIR */ 327 && keyCode == KeyEvent.KEYCODE_BACK 328 && event.getRepeatCount() == 0) { 329 // Take care of calling this method on earlier versions of 330 // the platform where it doesn't exist. 331 onBackPressed(); 332 return true; 333 } 334 335 return super.onKeyDown(keyCode, event); 336 } 337 338 /** 339 * Dispatch onLowMemory() to all fragments. 340 */ 341 @Override 342 public void onLowMemory() { 343 super.onLowMemory(); 344 mFragments.dispatchLowMemory(); 345 } 346 347 /** 348 * Dispatch context and options menu to fragments. 349 */ 350 @Override 351 public boolean onMenuItemSelected(int featureId, MenuItem item) { 352 if (super.onMenuItemSelected(featureId, item)) { 353 return true; 354 } 355 356 switch (featureId) { 357 case Window.FEATURE_OPTIONS_PANEL: 358 return mFragments.dispatchOptionsItemSelected(item); 359 360 case Window.FEATURE_CONTEXT_MENU: 361 return mFragments.dispatchContextItemSelected(item); 362 363 default: 364 return false; 365 } 366 } 367 368 /** 369 * Call onOptionsMenuClosed() on fragments. 370 */ 371 @Override 372 public void onPanelClosed(int featureId, Menu menu) { 373 switch (featureId) { 374 case Window.FEATURE_OPTIONS_PANEL: 375 mFragments.dispatchOptionsMenuClosed(menu); 376 break; 377 } 378 super.onPanelClosed(featureId, menu); 379 } 380 381 /** 382 * Dispatch onPause() to fragments. 383 */ 384 @Override 385 protected void onPause() { 386 super.onPause(); 387 mResumed = false; 388 if (mHandler.hasMessages(MSG_RESUME_PENDING)) { 389 mHandler.removeMessages(MSG_RESUME_PENDING); 390 mFragments.dispatchResume(); 391 } 392 mFragments.dispatchPause(); 393 } 394 395 /** 396 * Dispatch onResume() to fragments. 397 */ 398 @Override 399 protected void onResume() { 400 super.onResume(); 401 mHandler.sendEmptyMessage(MSG_RESUME_PENDING); 402 mResumed = true; 403 mFragments.execPendingActions(); 404 } 405 406 /** 407 * Dispatch onResume() to fragments. 408 */ 409 @Override 410 protected void onPostResume() { 411 super.onPostResume(); 412 mHandler.removeMessages(MSG_RESUME_PENDING); 413 mFragments.dispatchResume(); 414 mFragments.execPendingActions(); 415 } 416 417 /** 418 * Dispatch onPrepareOptionsMenu() to fragments. 419 */ 420 @Override 421 public boolean onPreparePanel(int featureId, View view, Menu menu) { 422 if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) { 423 if (mOptionsMenuInvalidated) { 424 mOptionsMenuInvalidated = false; 425 menu.clear(); 426 onCreatePanelMenu(featureId, menu); 427 } 428 boolean goforit = super.onPreparePanel(featureId, view, menu); 429 goforit |= mFragments.dispatchPrepareOptionsMenu(menu); 430 return goforit && menu.hasVisibleItems(); 431 } 432 return super.onPreparePanel(featureId, view, menu); 433 } 434 435 /** 436 * Retain all appropriate fragment and loader state. You can NOT 437 * override this yourself! Use {@link #onRetainCustomNonConfigurationInstance()} 438 * if you want to retain your own state. 439 */ 440 @Override 441 public final Object onRetainNonConfigurationInstance() { 442 if (mStopped) { 443 doReallyStop(true); 444 } 445 446 Object custom = onRetainCustomNonConfigurationInstance(); 447 448 ArrayList<Fragment> fragments = mFragments.retainNonConfig(); 449 boolean retainLoaders = false; 450 if (mAllLoaderManagers != null) { 451 // prune out any loader managers that were already stopped and so 452 // have nothing useful to retain. 453 for (int i=mAllLoaderManagers.size()-1; i>=0; i--) { 454 LoaderManagerImpl lm = mAllLoaderManagers.valueAt(i); 455 if (lm.mRetaining) { 456 retainLoaders = true; 457 } else { 458 lm.doDestroy(); 459 mAllLoaderManagers.removeAt(i); 460 } 461 } 462 } 463 if (fragments == null && !retainLoaders && custom == null) { 464 return null; 465 } 466 467 NonConfigurationInstances nci = new NonConfigurationInstances(); 468 nci.activity = null; 469 nci.custom = custom; 470 nci.children = null; 471 nci.fragments = fragments; 472 nci.loaders = mAllLoaderManagers; 473 return nci; 474 } 475 476 /** 477 * Save all appropriate fragment state. 478 */ 479 @Override 480 protected void onSaveInstanceState(Bundle outState) { 481 super.onSaveInstanceState(outState); 482 Parcelable p = mFragments.saveAllState(); 483 if (p != null) { 484 outState.putParcelable(FRAGMENTS_TAG, p); 485 } 486 } 487 488 /** 489 * Dispatch onStart() to all fragments. Ensure any created loaders are 490 * now started. 491 */ 492 @Override 493 protected void onStart() { 494 super.onStart(); 495 496 mStopped = false; 497 mReallyStopped = false; 498 mHandler.removeMessages(MSG_REALLY_STOPPED); 499 500 if (!mCreated) { 501 mCreated = true; 502 mFragments.dispatchActivityCreated(); 503 } 504 505 mFragments.noteStateNotSaved(); 506 mFragments.execPendingActions(); 507 508 if (!mLoadersStarted) { 509 mLoadersStarted = true; 510 if (mLoaderManager != null) { 511 mLoaderManager.doStart(); 512 } else if (!mCheckedForLoaderManager) { 513 mLoaderManager = getLoaderManager(-1, mLoadersStarted, false); 514 // the returned loader manager may be a new one, so we have to start it 515 if ((mLoaderManager != null) && (!mLoaderManager.mStarted)) { 516 mLoaderManager.doStart(); 517 } 518 } 519 mCheckedForLoaderManager = true; 520 } 521 // NOTE: HC onStart goes here. 522 523 mFragments.dispatchStart(); 524 if (mAllLoaderManagers != null) { 525 for (int i=mAllLoaderManagers.size()-1; i>=0; i--) { 526 LoaderManagerImpl lm = mAllLoaderManagers.valueAt(i); 527 lm.finishRetain(); 528 lm.doReportStart(); 529 } 530 } 531 } 532 533 /** 534 * Dispatch onStop() to all fragments. Ensure all loaders are stopped. 535 */ 536 @Override 537 protected void onStop() { 538 super.onStop(); 539 540 mStopped = true; 541 mHandler.sendEmptyMessage(MSG_REALLY_STOPPED); 542 543 mFragments.dispatchStop(); 544 } 545 546 // ------------------------------------------------------------------------ 547 // NEW METHODS 548 // ------------------------------------------------------------------------ 549 550 /** 551 * Use this instead of {@link #onRetainNonConfigurationInstance()}. 552 * Retrieve later with {@link #getLastCustomNonConfigurationInstance()}. 553 */ 554 public Object onRetainCustomNonConfigurationInstance() { 555 return null; 556 } 557 558 /** 559 * Return the value previously returned from 560 * {@link #onRetainCustomNonConfigurationInstance()}. 561 */ 562 public Object getLastCustomNonConfigurationInstance() { 563 NonConfigurationInstances nc = (NonConfigurationInstances) 564 getLastNonConfigurationInstance(); 565 return nc != null ? nc.custom : null; 566 } 567 568 /** 569 * Invalidate the activity's options menu. This will cause relevant presentations 570 * of the menu to fully update via calls to onCreateOptionsMenu and 571 * onPrepareOptionsMenu the next time the menu is requested. 572 */ 573 public void supportInvalidateOptionsMenu() { 574 if (android.os.Build.VERSION.SDK_INT >= HONEYCOMB) { 575 // If we are running on HC or greater, we can use the framework 576 // API to invalidate the options menu. 577 ActivityCompatHoneycomb.invalidateOptionsMenu(this); 578 return; 579 } 580 581 // Whoops, older platform... we'll use a hack, to manually rebuild 582 // the options menu the next time it is prepared. 583 mOptionsMenuInvalidated = true; 584 } 585 586 /** 587 * Print the Activity's state into the given stream. This gets invoked if 588 * you run "adb shell dumpsys activity <activity_component_name>". 589 * 590 * @param prefix Desired prefix to prepend at each line of output. 591 * @param fd The raw file descriptor that the dump is being sent to. 592 * @param writer The PrintWriter to which you should dump your state. This will be 593 * closed for you after you return. 594 * @param args additional arguments to the dump request. 595 */ 596 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 597 if (android.os.Build.VERSION.SDK_INT >= HONEYCOMB) { 598 // XXX This can only work if we can call the super-class impl. :/ 599 //ActivityCompatHoneycomb.dump(this, prefix, fd, writer, args); 600 } 601 writer.print(prefix); writer.print("Local FragmentActivity "); 602 writer.print(Integer.toHexString(System.identityHashCode(this))); 603 writer.println(" State:"); 604 String innerPrefix = prefix + " "; 605 writer.print(innerPrefix); writer.print("mCreated="); 606 writer.print(mCreated); writer.print("mResumed="); 607 writer.print(mResumed); writer.print(" mStopped="); 608 writer.print(mStopped); writer.print(" mReallyStopped="); 609 writer.println(mReallyStopped); 610 writer.print(innerPrefix); writer.print("mLoadersStarted="); 611 writer.println(mLoadersStarted); 612 if (mLoaderManager != null) { 613 writer.print(prefix); writer.print("Loader Manager "); 614 writer.print(Integer.toHexString(System.identityHashCode(mLoaderManager))); 615 writer.println(":"); 616 mLoaderManager.dump(prefix + " ", fd, writer, args); 617 } 618 mFragments.dump(prefix, fd, writer, args); 619 } 620 621 void doReallyStop(boolean retaining) { 622 if (!mReallyStopped) { 623 mReallyStopped = true; 624 mRetaining = retaining; 625 mHandler.removeMessages(MSG_REALLY_STOPPED); 626 onReallyStop(); 627 } 628 } 629 630 /** 631 * Pre-HC, we didn't have a way to determine whether an activity was 632 * being stopped for a config change or not until we saw 633 * onRetainNonConfigurationInstance() called after onStop(). However 634 * we need to know this, to know whether to retain fragments. This will 635 * tell us what we need to know. 636 */ 637 void onReallyStop() { 638 if (mLoadersStarted) { 639 mLoadersStarted = false; 640 if (mLoaderManager != null) { 641 if (!mRetaining) { 642 mLoaderManager.doStop(); 643 } else { 644 mLoaderManager.doRetain(); 645 } 646 } 647 } 648 649 mFragments.dispatchReallyStop(); 650 } 651 652 // ------------------------------------------------------------------------ 653 // FRAGMENT SUPPORT 654 // ------------------------------------------------------------------------ 655 656 /** 657 * Called when a fragment is attached to the activity. 658 */ 659 public void onAttachFragment(Fragment fragment) { 660 } 661 662 /** 663 * Return the FragmentManager for interacting with fragments associated 664 * with this activity. 665 */ 666 public FragmentManager getSupportFragmentManager() { 667 return mFragments; 668 } 669 670 /** 671 * Modifies the standard behavior to allow results to be delivered to fragments. 672 * This imposes a restriction that requestCode be <= 0xffff. 673 */ 674 @Override 675 public void startActivityForResult(Intent intent, int requestCode) { 676 if (requestCode != -1 && (requestCode&0xffff0000) != 0) { 677 throw new IllegalArgumentException("Can only use lower 16 bits for requestCode"); 678 } 679 super.startActivityForResult(intent, requestCode); 680 } 681 682 /** 683 * Called by Fragment.startActivityForResult() to implement its behavior. 684 */ 685 public void startActivityFromFragment(Fragment fragment, Intent intent, 686 int requestCode) { 687 if (requestCode == -1) { 688 super.startActivityForResult(intent, -1); 689 return; 690 } 691 if ((requestCode&0xffff0000) != 0) { 692 throw new IllegalArgumentException("Can only use lower 16 bits for requestCode"); 693 } 694 super.startActivityForResult(intent, ((fragment.mIndex+1)<<16) + (requestCode&0xffff)); 695 } 696 697 void invalidateSupportFragmentIndex(int index) { 698 //Log.v(TAG, "invalidateFragmentIndex: index=" + index); 699 if (mAllLoaderManagers != null) { 700 LoaderManagerImpl lm = mAllLoaderManagers.get(index); 701 if (lm != null && !lm.mRetaining) { 702 lm.doDestroy(); 703 mAllLoaderManagers.remove(index); 704 } 705 } 706 } 707 708 // ------------------------------------------------------------------------ 709 // LOADER SUPPORT 710 // ------------------------------------------------------------------------ 711 712 /** 713 * Return the LoaderManager for this fragment, creating it if needed. 714 */ 715 public LoaderManager getSupportLoaderManager() { 716 if (mLoaderManager != null) { 717 return mLoaderManager; 718 } 719 mCheckedForLoaderManager = true; 720 mLoaderManager = getLoaderManager(-1, mLoadersStarted, true); 721 return mLoaderManager; 722 } 723 724 LoaderManagerImpl getLoaderManager(int index, boolean started, boolean create) { 725 if (mAllLoaderManagers == null) { 726 mAllLoaderManagers = new HCSparseArray<LoaderManagerImpl>(); 727 } 728 LoaderManagerImpl lm = mAllLoaderManagers.get(index); 729 if (lm == null) { 730 if (create) { 731 lm = new LoaderManagerImpl(this, started); 732 mAllLoaderManagers.put(index, lm); 733 } 734 } else { 735 lm.updateActivity(this); 736 } 737 return lm; 738 } 739} 740