public <D> Loader<D> restartLoader( int paramInt, Bundle paramBundle, LoaderManager.LoaderCallbacks<D> paramLoaderCallbacks) { if (this.mCreatingLoader) { throw new IllegalStateException("Called while creating a loader"); } LoaderInfo localLoaderInfo1 = (LoaderInfo) this.mLoaders.get(paramInt); if (DEBUG) { Log.v("LoaderManager", "restartLoader in " + this + ": args=" + paramBundle); } if (localLoaderInfo1 != null) { LoaderInfo localLoaderInfo2 = (LoaderInfo) this.mInactiveLoaders.get(paramInt); if (localLoaderInfo2 == null) { break label329; } if (!localLoaderInfo1.mHaveData) { break label175; } if (DEBUG) { Log.v("LoaderManager", " Removing last inactive loader: " + localLoaderInfo1); } localLoaderInfo2.mDeliveredData = false; localLoaderInfo2.destroy(); localLoaderInfo1.mLoader.abandon(); this.mInactiveLoaders.put(paramInt, localLoaderInfo1); } for (; ; ) { return createAndInstallLoader(paramInt, paramBundle, paramLoaderCallbacks).mLoader; label175: if (!localLoaderInfo1.mStarted) { if (DEBUG) { Log.v("LoaderManager", " Current loader is stopped; replacing"); } this.mLoaders.put(paramInt, null); localLoaderInfo1.destroy(); } else { if (DEBUG) { Log.v("LoaderManager", " Current loader is running; attempting to cancel"); } localLoaderInfo1.cancel(); if (localLoaderInfo1.mPendingLoader != null) { if (DEBUG) { Log.v("LoaderManager", " Removing pending loader: " + localLoaderInfo1.mPendingLoader); } localLoaderInfo1.mPendingLoader.destroy(); localLoaderInfo1.mPendingLoader = null; } if (DEBUG) { Log.v("LoaderManager", " Enqueuing as new pending loader"); } localLoaderInfo1.mPendingLoader = createLoader(paramInt, paramBundle, paramLoaderCallbacks); return localLoaderInfo1.mPendingLoader.mLoader; label329: if (DEBUG) { Log.v("LoaderManager", " Making last loader inactive: " + localLoaderInfo1); } localLoaderInfo1.mLoader.abandon(); this.mInactiveLoaders.put(paramInt, localLoaderInfo1); } } }
public void destroyLoader(int paramInt) { if (this.mCreatingLoader) throw new IllegalStateException("Called while creating a loader"); if (DEBUG) { String str = "destroyLoader in " + this + " of " + paramInt; int i = Log.v("LoaderManager", str); } int j = this.mLoaders.indexOfKey(paramInt); if (j >= 0) { LoaderInfo localLoaderInfo1 = (LoaderInfo)this.mLoaders.valueAt(j); this.mLoaders.removeAt(j); localLoaderInfo1.destroy(); } int k = this.mInactiveLoaders.indexOfKey(paramInt); if (k >= 0) { LoaderInfo localLoaderInfo2 = (LoaderInfo)this.mInactiveLoaders.valueAt(k); this.mInactiveLoaders.removeAt(k); localLoaderInfo2.destroy(); } if (this.mActivity == null) return; if (hasRunningLoaders()) return; this.mActivity.mFragments.startPendingDeferredFragments(); }
/** * Call to re-create the Loader associated with a particular ID. If there is currently a Loader * associated with this ID, it will be canceled/stopped/destroyed as appropriate. A new Loader * with the given arguments will be created and its data delivered to you once available. * * <p>This function does some throttling of Loaders. If too many Loaders have been created for the * given ID but not yet generated their data, new calls to this function will create and return a * new Loader but not actually start it until some previous loaders have completed. * * <p>After calling this function, any previous Loaders associated with this ID will be considered * invalid, and you will receive no further data updates from them. * * @param id A unique (to this LoaderManager instance) identifier under which to manage the new * Loader. * @param args Optional arguments that will be propagated to {@link * LoaderCallbacks#onCreateLoader(int, Bundle) LoaderCallbacks.onCreateLoader()}. * @param callback Interface implementing management of this Loader. Required. Its * onCreateLoader() method will be called while inside of the function to instantiate the * Loader object. */ @SuppressWarnings("unchecked") public <D> Loader<D> restartLoader( int id, Bundle args, LoaderManager.LoaderCallbacks<D> callback) { if (mCreatingLoader) { throw new IllegalStateException("Called while creating a loader"); } LoaderInfo info = mLoaders.get(id); if (DEBUG) Log.v(TAG, "restartLoader in " + this + ": args=" + args); if (info != null) { LoaderInfo inactive = mInactiveLoaders.get(id); if (inactive != null) { if (info.mHaveData) { // This loader now has data... we are probably being // called from within onLoadComplete, where we haven't // yet destroyed the last inactive loader. So just do // that now. if (DEBUG) Log.v(TAG, " Removing last inactive loader: " + info); inactive.mDeliveredData = false; inactive.destroy(); info.mLoader.abandon(); mInactiveLoaders.put(id, info); } else { // We already have an inactive loader for this ID that we are // waiting for! What to do, what to do... if (!info.mStarted) { // The current Loader has not been started... we thus // have no reason to keep it around, so bam, slam, // thank-you-ma'am. if (DEBUG) Log.v(TAG, " Current loader is stopped; replacing"); mLoaders.put(id, null); info.destroy(); } else { // Now we have three active loaders... we'll queue // up this request to be processed once one of the other loaders // finishes. if (info.mPendingLoader != null) { if (DEBUG) Log.v(TAG, " Removing pending loader: " + info.mPendingLoader); info.mPendingLoader.destroy(); info.mPendingLoader = null; } if (DEBUG) Log.v(TAG, " Enqueuing as new pending loader"); info.mPendingLoader = createLoader(id, args, (LoaderManager.LoaderCallbacks<Object>) callback); return (Loader<D>) info.mPendingLoader.mLoader; } } } else { // Keep track of the previous instance of this loader so we can destroy // it when the new one completes. if (DEBUG) Log.v(TAG, " Making last loader inactive: " + info); info.mLoader.abandon(); mInactiveLoaders.put(id, info); } } info = createAndInstallLoader(id, args, (LoaderManager.LoaderCallbacks<Object>) callback); return (Loader<D>) info.mLoader; }
void destroy() { if (DEBUG) Log.v(TAG, " Destroying: " + this); mDestroyed = true; boolean needReset = mDeliveredData; mDeliveredData = false; if (mCallbacks != null && mLoader != null && mHaveData && needReset) { if (DEBUG) Log.v(TAG, " Reseting: " + this); String lastBecause = null; if (mActivity != null) { lastBecause = mActivity.mFragments.mNoTransactionsBecause; mActivity.mFragments.mNoTransactionsBecause = "onLoaderReset"; } try { mCallbacks.onLoaderReset(mLoader); } finally { if (mActivity != null) { mActivity.mFragments.mNoTransactionsBecause = lastBecause; } } } mCallbacks = null; mData = null; mHaveData = false; if (mLoader != null) { if (mListenerRegistered) { mListenerRegistered = false; mLoader.unregisterListener(this); } mLoader.reset(); } if (mPendingLoader != null) { mPendingLoader.destroy(); } }
/** * Rip down, tear apart, shred to pieces a current Loader ID. After returning from this function, * any Loader objects associated with this ID are destroyed. Any data associated with them is * destroyed. You better not be using it when you do this. * * @param id Identifier of the Loader to be destroyed. */ public void destroyLoader(int id) { if (mCreatingLoader) { throw new IllegalStateException("Called while creating a loader"); } if (DEBUG) Log.v(TAG, "destroyLoader in " + this + " of " + id); int idx = mLoaders.indexOfKey(id); if (idx >= 0) { LoaderInfo info = mLoaders.valueAt(idx); mLoaders.removeAt(idx); info.destroy(); } idx = mInactiveLoaders.indexOfKey(id); if (idx >= 0) { LoaderInfo info = mInactiveLoaders.valueAt(idx); mInactiveLoaders.removeAt(idx); info.destroy(); } }
@Override public void onLoadComplete(Loader<Object> loader, Object data) { if (DEBUG) Log.v(TAG, "onLoadComplete: " + this); if (mDestroyed) { if (DEBUG) Log.v(TAG, " Ignoring load complete -- destroyed"); return; } if (mLoaders.get(mId) != this) { // This data is not coming from the current active loader. // We don't care about it. if (DEBUG) Log.v(TAG, " Ignoring load complete -- not active"); return; } LoaderInfo pending = mPendingLoader; if (pending != null) { // There is a new request pending and we were just // waiting for the old one to complete before starting // it. So now it is time, switch over to the new loader. if (DEBUG) Log.v(TAG, " Switching to pending loader: " + pending); mPendingLoader = null; mLoaders.put(mId, null); destroy(); installLoader(pending); return; } // Notify of the new data so the app can switch out the old data before // we try to destroy it. if (mData != data || !mHaveData) { mData = data; mHaveData = true; if (mStarted) { callOnLoadFinished(loader, data); } } // if (DEBUG) Log.v(TAG, " onLoadFinished returned: " + this); // We have now given the application the new loader with its // loaded data, so it should have stopped using the previous // loader. If there is a previous loader on the inactive list, // clean it up. LoaderInfo info = mInactiveLoaders.get(mId); if (info != null && info != this) { info.mDeliveredData = false; info.destroy(); mInactiveLoaders.remove(mId); } }
public void destroyLoader(int paramInt) { if (this.mCreatingLoader) { throw new IllegalStateException("Called while creating a loader"); } if (DEBUG) { Log.v("LoaderManager", "destroyLoader in " + this + " of " + paramInt); } int i = this.mLoaders.indexOfKey(paramInt); LoaderInfo localLoaderInfo; if (i >= 0) { localLoaderInfo = (LoaderInfo) this.mLoaders.valueAt(i); this.mLoaders.removeAt(i); localLoaderInfo.destroy(); } paramInt = this.mInactiveLoaders.indexOfKey(paramInt); if (paramInt >= 0) { localLoaderInfo = (LoaderInfo) this.mInactiveLoaders.valueAt(paramInt); this.mInactiveLoaders.removeAt(paramInt); localLoaderInfo.destroy(); } if ((this.mHost != null) && (!hasRunningLoaders())) { this.mHost.mFragmentManager.startPendingDeferredFragments(); } }
public void onLoadComplete(Loader<Object> paramLoader, Object paramObject) { if (LoaderManagerImpl.DEBUG) { String str1 = "onLoadComplete: " + this; int i = Log.v("LoaderManager", str1); } if (this.mDestroyed) { if (!LoaderManagerImpl.DEBUG) return; int j = Log.v("LoaderManager", " Ignoring load complete -- destroyed"); return; } SparseArrayCompat localSparseArrayCompat1 = LoaderManagerImpl.this.mLoaders; int k = this.mId; if (localSparseArrayCompat1.get(k) != this) { if (!LoaderManagerImpl.DEBUG) return; int m = Log.v("LoaderManager", " Ignoring load complete -- not active"); return; } LoaderInfo localLoaderInfo1 = this.mPendingLoader; if (localLoaderInfo1 != null) { if (LoaderManagerImpl.DEBUG) { String str2 = " Switching to pending loader: " + localLoaderInfo1; int n = Log.v("LoaderManager", str2); } this.mPendingLoader = null; SparseArrayCompat localSparseArrayCompat2 = LoaderManagerImpl.this.mLoaders; int i1 = this.mId; localSparseArrayCompat2.put(i1, null); destroy(); LoaderManagerImpl.this.installLoader(localLoaderInfo1); return; } if ((this.mData != paramObject) || (!this.mHaveData)) { this.mData = paramObject; this.mHaveData = true; if (this.mStarted) callOnLoadFinished(paramLoader, paramObject); } SparseArrayCompat localSparseArrayCompat3 = LoaderManagerImpl.this.mInactiveLoaders; int i2 = this.mId; LoaderInfo localLoaderInfo2 = (LoaderInfo)localSparseArrayCompat3.get(i2); if ((localLoaderInfo2 != null) && (localLoaderInfo2 != this)) { localLoaderInfo2.mDeliveredData = false; localLoaderInfo2.destroy(); SparseArrayCompat localSparseArrayCompat4 = LoaderManagerImpl.this.mInactiveLoaders; int i3 = this.mId; localSparseArrayCompat4.remove(i3); } if (LoaderManagerImpl.this.mActivity == null) return; if (LoaderManagerImpl.this.hasRunningLoaders()) return; LoaderManagerImpl.this.mActivity.mFragments.startPendingDeferredFragments(); }
public <D> Loader<D> restartLoader(int paramInt, Bundle paramBundle, LoaderManager.LoaderCallbacks<D> paramLoaderCallbacks) { if (this.mCreatingLoader) throw new IllegalStateException("Called while creating a loader"); LoaderInfo localLoaderInfo1 = (LoaderInfo)this.mLoaders.get(paramInt); if (DEBUG) { String str1 = "restartLoader in " + this + ": args=" + paramBundle; int i = Log.v("LoaderManager", str1); } if (localLoaderInfo1 != null) { LoaderInfo localLoaderInfo2 = (LoaderInfo)this.mInactiveLoaders.get(paramInt); if (localLoaderInfo2 == null) break label346; if (!localLoaderInfo1.mHaveData) break label189; if (DEBUG) { String str2 = " Removing last inactive loader: " + localLoaderInfo1; int j = Log.v("LoaderManager", str2); } localLoaderInfo2.mDeliveredData = false; localLoaderInfo2.destroy(); localLoaderInfo1.mLoader.abandon(); this.mInactiveLoaders.put(paramInt, localLoaderInfo1); } while (true) { for (Loader localLoader = createAndInstallLoader(paramInt, paramBundle, paramLoaderCallbacks).mLoader; ; localLoader = localLoaderInfo1.mPendingLoader.mLoader) { return localLoader; label189: if (!localLoaderInfo1.mStarted) { if (DEBUG) int k = Log.v("LoaderManager", " Current loader is stopped; replacing"); this.mLoaders.put(paramInt, null); localLoaderInfo1.destroy(); break; } if (localLoaderInfo1.mPendingLoader != null) { if (DEBUG) { StringBuilder localStringBuilder = new StringBuilder().append(" Removing pending loader: "); LoaderInfo localLoaderInfo3 = localLoaderInfo1.mPendingLoader; String str3 = localLoaderInfo3; int m = Log.v("LoaderManager", str3); } localLoaderInfo1.mPendingLoader.destroy(); localLoaderInfo1.mPendingLoader = null; } if (DEBUG) int n = Log.v("LoaderManager", " Enqueuing as new pending loader"); LoaderInfo localLoaderInfo4 = createLoader(paramInt, paramBundle, paramLoaderCallbacks); localLoaderInfo1.mPendingLoader = localLoaderInfo4; } label346: if (DEBUG) { String str4 = " Making last loader inactive: " + localLoaderInfo1; int i1 = Log.v("LoaderManager", str4); } localLoaderInfo1.mLoader.abandon(); this.mInactiveLoaders.put(paramInt, localLoaderInfo1); } }