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