Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 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 | |
| 17 | package android.app; |
| 18 | |
| 19 | import android.content.Loader; |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 20 | import android.os.Bundle; |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 21 | import android.util.Log; |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 22 | import android.util.SparseArray; |
| 23 | |
| 24 | /** |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 25 | * Interface associated with an {@link Activity} or {@link Fragment} for managing |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 26 | * one or more {@link android.content.Loader} instances associated with it. |
| 27 | */ |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 28 | public interface LoaderManager { |
| 29 | /** |
| 30 | * Callback interface for a client to interact with the manager. |
| 31 | */ |
| 32 | public interface LoaderCallbacks<D> { |
| 33 | /** |
| 34 | * Instantiate and return a new Loader for the given ID. |
| 35 | * |
| 36 | * @param id The ID whose loader is to be created. |
| 37 | * @param args Any arguments supplied by the caller. |
| 38 | * @return Return a new Loader instance that is ready to start loading. |
| 39 | */ |
| 40 | public Loader<D> onCreateLoader(int id, Bundle args); |
| 41 | |
| 42 | /** |
| 43 | * Called when a previously created loader has finished its load. |
| 44 | * @param loader The Loader that has finished. |
| 45 | * @param data The data generated by the Loader. |
| 46 | */ |
| 47 | public void onLoadFinished(Loader<D> loader, D data); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Ensures a loader is initialized and active. If the loader doesn't |
| 52 | * already exist, one is created and (if the activity/fragment is currently |
| 53 | * started) starts the loader. Otherwise the last created |
| 54 | * loader is re-used. |
| 55 | * |
| 56 | * <p>In either case, the given callback is associated with the loader, and |
| 57 | * will be called as the loader state changes. If at the point of call |
| 58 | * the caller is in its started state, and the requested loader |
| 59 | * already exists and has generated its data, then |
| 60 | * callback. {@link LoaderCallbacks#onLoadFinished} will |
| 61 | * be called immediately (inside of this function), so you must be prepared |
| 62 | * for this to happen. |
| 63 | */ |
| 64 | public <D> Loader<D> initLoader(int id, Bundle args, |
| 65 | LoaderManager.LoaderCallbacks<D> callback); |
| 66 | |
| 67 | /** |
| 68 | * Creates a new loader in this manager, registers the callbacks to it, |
| 69 | * and (if the activity/fragment is currently started) starts loading it. |
| 70 | * If a loader with the same id has previously been |
| 71 | * started it will automatically be destroyed when the new loader completes |
| 72 | * its work. The callback will be delivered before the old loader |
| 73 | * is destroyed. |
| 74 | */ |
| 75 | public <D> Loader<D> restartLoader(int id, Bundle args, |
| 76 | LoaderManager.LoaderCallbacks<D> callback); |
| 77 | |
| 78 | /** |
| 79 | * Stops and removes the loader with the given ID. |
| 80 | */ |
| 81 | public void stopLoader(int id); |
| 82 | |
| 83 | /** |
| 84 | * Return the Loader with the given id or null if no matching Loader |
| 85 | * is found. |
| 86 | */ |
| 87 | public <D> Loader<D> getLoader(int id); |
| 88 | } |
| 89 | |
| 90 | class LoaderManagerImpl implements LoaderManager { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 91 | static final String TAG = "LoaderManagerImpl"; |
| 92 | static final boolean DEBUG = true; |
| 93 | |
| 94 | // These are the currently active loaders. A loader is here |
| 95 | // from the time its load is started until it has been explicitly |
| 96 | // stopped or restarted by the application. |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 97 | final SparseArray<LoaderInfo> mLoaders = new SparseArray<LoaderInfo>(); |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 98 | |
| 99 | // These are previously run loaders. This list is maintained internally |
| 100 | // to avoid destroying a loader while an application is still using it. |
| 101 | // It allows an application to restart a loader, but continue using its |
| 102 | // previously run loader until the new loader's data is available. |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 103 | final SparseArray<LoaderInfo> mInactiveLoaders = new SparseArray<LoaderInfo>(); |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 104 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 105 | boolean mStarted; |
| 106 | boolean mRetaining; |
| 107 | boolean mRetainingStarted; |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 108 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 109 | final class LoaderInfo implements Loader.OnLoadCompleteListener<Object> { |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 110 | final int mId; |
| 111 | final Bundle mArgs; |
| 112 | LoaderManager.LoaderCallbacks<Object> mCallbacks; |
| 113 | Loader<Object> mLoader; |
| 114 | Object mData; |
| 115 | boolean mStarted; |
| 116 | boolean mRetaining; |
| 117 | boolean mRetainingStarted; |
| 118 | boolean mDestroyed; |
| 119 | boolean mListenerRegistered; |
| 120 | |
| 121 | public LoaderInfo(int id, Bundle args, LoaderManager.LoaderCallbacks<Object> callbacks) { |
| 122 | mId = id; |
| 123 | mArgs = args; |
| 124 | mCallbacks = callbacks; |
| 125 | } |
| 126 | |
| 127 | void start() { |
| 128 | if (mRetaining && mRetainingStarted) { |
| 129 | // Our owner is started, but we were being retained from a |
| 130 | // previous instance in the started state... so there is really |
| 131 | // nothing to do here, since the loaders are still started. |
| 132 | mStarted = true; |
| 133 | return; |
| 134 | } |
| 135 | |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 136 | if (mStarted) { |
| 137 | // If loader already started, don't restart. |
| 138 | return; |
| 139 | } |
| 140 | |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 141 | if (DEBUG) Log.v(TAG, " Starting: " + this); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 142 | if (mLoader == null && mCallbacks != null) { |
| 143 | mLoader = mCallbacks.onCreateLoader(mId, mArgs); |
| 144 | } |
| 145 | if (mLoader != null) { |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 146 | if (!mListenerRegistered) { |
| 147 | mLoader.registerListener(mId, this); |
| 148 | mListenerRegistered = true; |
| 149 | } |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 150 | mLoader.startLoading(); |
| 151 | mStarted = true; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void retain() { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 156 | if (DEBUG) Log.v(TAG, " Retaining: " + this); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 157 | mRetaining = true; |
| 158 | mRetainingStarted = mStarted; |
| 159 | mStarted = false; |
| 160 | mCallbacks = null; |
| 161 | } |
| 162 | |
| 163 | void finishRetain() { |
| 164 | if (mRetaining) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 165 | if (DEBUG) Log.v(TAG, " Finished Retaining: " + this); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 166 | mRetaining = false; |
| 167 | if (mStarted != mRetainingStarted) { |
| 168 | if (!mStarted) { |
| 169 | // This loader was retained in a started state, but |
| 170 | // at the end of retaining everything our owner is |
| 171 | // no longer started... so make it stop. |
| 172 | stop(); |
| 173 | } |
| 174 | } |
| 175 | if (mStarted && mData != null && mCallbacks != null) { |
| 176 | // This loader was retained, and now at the point of |
| 177 | // finishing the retain we find we remain started, have |
| 178 | // our data, and the owner has a new callback... so |
| 179 | // let's deliver the data now. |
| 180 | mCallbacks.onLoadFinished(mLoader, mData); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void stop() { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 186 | if (DEBUG) Log.v(TAG, " Stopping: " + this); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 187 | mStarted = false; |
Dianne Hackborn | debb2e2 | 2010-08-09 16:32:52 -0700 | [diff] [blame] | 188 | if (!mRetaining) { |
| 189 | if (mLoader != null && mListenerRegistered) { |
| 190 | // Let the loader know we're done with it |
| 191 | mListenerRegistered = false; |
| 192 | mLoader.unregisterListener(this); |
| 193 | mLoader.stopLoading(); |
| 194 | } |
| 195 | mData = null; |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | void destroy() { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 200 | if (DEBUG) Log.v(TAG, " Destroying: " + this); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 201 | mDestroyed = true; |
| 202 | mCallbacks = null; |
| 203 | if (mLoader != null) { |
| 204 | if (mListenerRegistered) { |
| 205 | mListenerRegistered = false; |
| 206 | mLoader.unregisterListener(this); |
| 207 | } |
| 208 | mLoader.destroy(); |
| 209 | } |
| 210 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 211 | |
| 212 | @Override public void onLoadComplete(Loader<Object> loader, Object data) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 213 | if (DEBUG) Log.v(TAG, "onLoadComplete: " + this + " mDestroyed=" + mDestroyed); |
| 214 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 215 | if (mDestroyed) { |
| 216 | return; |
| 217 | } |
| 218 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 219 | // Notify of the new data so the app can switch out the old data before |
| 220 | // we try to destroy it. |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 221 | mData = data; |
| 222 | if (mCallbacks != null) { |
| 223 | mCallbacks.onLoadFinished(loader, data); |
| 224 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 225 | |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 226 | if (DEBUG) Log.v(TAG, "onLoadFinished returned: " + this); |
| 227 | |
| 228 | // We have now given the application the new loader with its |
| 229 | // loaded data, so it should have stopped using the previous |
| 230 | // loader. If there is a previous loader on the inactive list, |
| 231 | // clean it up. |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 232 | LoaderInfo info = mInactiveLoaders.get(mId); |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 233 | if (info != null && info != this) { |
| 234 | info.destroy(); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 235 | mInactiveLoaders.remove(mId); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 236 | } |
| 237 | } |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 238 | |
| 239 | @Override |
| 240 | public String toString() { |
| 241 | StringBuilder sb = new StringBuilder(64); |
| 242 | sb.append("LoaderInfo{"); |
| 243 | sb.append(Integer.toHexString(System.identityHashCode(this))); |
| 244 | sb.append(" #"); |
| 245 | sb.append(mId); |
| 246 | if (mArgs != null) { |
| 247 | sb.append(" "); |
| 248 | sb.append(mArgs.toString()); |
| 249 | } |
| 250 | sb.append("}"); |
| 251 | return sb.toString(); |
| 252 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 253 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 254 | |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 255 | LoaderManagerImpl(boolean started) { |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 256 | mStarted = started; |
| 257 | } |
| 258 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 259 | private LoaderInfo createLoader(int id, Bundle args, |
| 260 | LoaderManager.LoaderCallbacks<Object> callback) { |
| 261 | LoaderInfo info = new LoaderInfo(id, args, (LoaderManager.LoaderCallbacks<Object>)callback); |
| 262 | mLoaders.put(id, info); |
| 263 | Loader<Object> loader = callback.onCreateLoader(id, args); |
| 264 | info.mLoader = (Loader<Object>)loader; |
| 265 | if (mStarted) { |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 266 | // The activity will start all existing loaders in it's onStart(), |
| 267 | // so only start them here if we're past that point of the activitiy's |
| 268 | // life cycle |
| 269 | info.start(); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 270 | } |
| 271 | return info; |
| 272 | } |
| 273 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 274 | @SuppressWarnings("unchecked") |
| 275 | public <D> Loader<D> initLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback) { |
| 276 | LoaderInfo info = mLoaders.get(id); |
| 277 | |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 278 | if (DEBUG) Log.v(TAG, "initLoader in " + this + ": cur=" + info); |
| 279 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 280 | if (info == null) { |
| 281 | // Loader doesn't already exist; create. |
| 282 | info = createLoader(id, args, (LoaderManager.LoaderCallbacks<Object>)callback); |
| 283 | } else { |
| 284 | info.mCallbacks = (LoaderManager.LoaderCallbacks<Object>)callback; |
| 285 | } |
| 286 | |
| 287 | if (info.mData != null && mStarted) { |
| 288 | // If the loader has already generated its data, report it now. |
| 289 | info.mCallbacks.onLoadFinished(info.mLoader, info.mData); |
| 290 | } |
| 291 | |
| 292 | return (Loader<D>)info.mLoader; |
| 293 | } |
| 294 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 295 | @SuppressWarnings("unchecked") |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 296 | public <D> Loader<D> restartLoader(int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback) { |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 297 | LoaderInfo info = mLoaders.get(id); |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 298 | if (DEBUG) Log.v(TAG, "restartLoader in " + this + ": cur=" + info); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 299 | if (info != null) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 300 | LoaderInfo inactive = mInactiveLoaders.get(id); |
| 301 | if (inactive != null) { |
| 302 | if (info.mData != null) { |
| 303 | // This loader now has data... we are probably being |
| 304 | // called from within onLoadComplete, where we haven't |
| 305 | // yet destroyed the last inactive loader. So just do |
| 306 | // that now. |
| 307 | if (DEBUG) Log.v(TAG, " Removing last inactive loader in " + this); |
| 308 | inactive.destroy(); |
| 309 | mInactiveLoaders.put(id, info); |
| 310 | } else { |
| 311 | // We already have an inactive loader for this ID that we are |
| 312 | // waiting for! Now we have three active loaders... let's just |
| 313 | // drop the one in the middle, since we are still waiting for |
| 314 | // its result but that result is already out of date. |
| 315 | if (DEBUG) Log.v(TAG, " Removing intermediate loader in " + this); |
| 316 | info.destroy(); |
| 317 | } |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 318 | } else { |
| 319 | // Keep track of the previous instance of this loader so we can destroy |
| 320 | // it when the new one completes. |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 321 | if (DEBUG) Log.v(TAG, " Making inactive: " + info); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 322 | mInactiveLoaders.put(id, info); |
| 323 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 324 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 325 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 326 | info = createLoader(id, args, (LoaderManager.LoaderCallbacks<Object>)callback); |
| 327 | return (Loader<D>)info.mLoader; |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 330 | public void stopLoader(int id) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 331 | if (DEBUG) Log.v(TAG, "stopLoader in " + this + " of " + id); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 332 | int idx = mLoaders.indexOfKey(id); |
| 333 | if (idx >= 0) { |
| 334 | LoaderInfo info = mLoaders.valueAt(idx); |
| 335 | mLoaders.removeAt(idx); |
Dianne Hackborn | 4911b78 | 2010-07-15 12:54:39 -0700 | [diff] [blame] | 336 | info.destroy(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 340 | @SuppressWarnings("unchecked") |
| 341 | public <D> Loader<D> getLoader(int id) { |
| 342 | LoaderInfo loaderInfo = mLoaders.get(id); |
| 343 | if (loaderInfo != null) { |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 344 | return (Loader<D>)mLoaders.get(id).mLoader; |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 345 | } |
| 346 | return null; |
| 347 | } |
| 348 | |
| 349 | void doStart() { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 350 | if (DEBUG) Log.v(TAG, "Starting: " + this); |
| 351 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 352 | // Call out to sub classes so they can start their loaders |
| 353 | // Let the existing loaders know that we want to be notified when a load is complete |
| 354 | for (int i = mLoaders.size()-1; i >= 0; i--) { |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 355 | mLoaders.valueAt(i).start(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 356 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 357 | mStarted = true; |
| 358 | } |
| 359 | |
| 360 | void doStop() { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 361 | if (DEBUG) Log.v(TAG, "Stopping: " + this); |
| 362 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 363 | for (int i = mLoaders.size()-1; i >= 0; i--) { |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 364 | mLoaders.valueAt(i).stop(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 365 | } |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 366 | mStarted = false; |
| 367 | } |
| 368 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 369 | void doRetain() { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 370 | if (DEBUG) Log.v(TAG, "Retaining: " + this); |
| 371 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 372 | mRetaining = true; |
| 373 | mStarted = false; |
| 374 | for (int i = mLoaders.size()-1; i >= 0; i--) { |
| 375 | mLoaders.valueAt(i).retain(); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | void finishRetain() { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 380 | if (DEBUG) Log.v(TAG, "Finished Retaining: " + this); |
| 381 | |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 382 | mRetaining = false; |
| 383 | for (int i = mLoaders.size()-1; i >= 0; i--) { |
| 384 | mLoaders.valueAt(i).finishRetain(); |
| 385 | } |
| 386 | } |
| 387 | |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 388 | void doDestroy() { |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 389 | if (!mRetaining) { |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 390 | if (DEBUG) Log.v(TAG, "Destroying Active: " + this); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 391 | for (int i = mLoaders.size()-1; i >= 0; i--) { |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 392 | mLoaders.valueAt(i).destroy(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 393 | } |
| 394 | } |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 395 | |
Dianne Hackborn | 5e0d595 | 2010-08-05 13:45:35 -0700 | [diff] [blame] | 396 | if (DEBUG) Log.v(TAG, "Destroying Inactive: " + this); |
Dianne Hackborn | 2707d60 | 2010-07-09 18:01:20 -0700 | [diff] [blame] | 397 | for (int i = mInactiveLoaders.size()-1; i >= 0; i--) { |
| 398 | mInactiveLoaders.valueAt(i).destroy(); |
| 399 | } |
| 400 | mInactiveLoaders.clear(); |
Dianne Hackborn | c801768 | 2010-07-06 13:34:38 -0700 | [diff] [blame] | 401 | } |
| 402 | } |