Merge "Fix a bug where restartLoader would result in a stuck loader" into nyc-dev am: 596a4a1
am: dd58799
* commit 'dd587993ae6eb5cb2b7949903444baf65cf746b5':
Fix a bug where restartLoader would result in a stuck loader
Change-Id: I0389cb4c45aa4cc6d42833e1c48b8c0e24ff9032
This commit is contained in:
@@ -339,13 +339,16 @@ class LoaderManagerImpl extends LoaderManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancel() {
|
boolean cancel() {
|
||||||
if (DEBUG) Log.v(TAG, " Canceling: " + this);
|
if (DEBUG) Log.v(TAG, " Canceling: " + this);
|
||||||
if (mStarted && mLoader != null && mListenerRegistered) {
|
if (mStarted && mLoader != null && mListenerRegistered) {
|
||||||
if (!mLoader.cancelLoad()) {
|
final boolean cancelLoadResult = mLoader.cancelLoad();
|
||||||
|
if (!cancelLoadResult) {
|
||||||
onLoadCanceled(mLoader);
|
onLoadCanceled(mLoader);
|
||||||
}
|
}
|
||||||
|
return cancelLoadResult;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy() {
|
void destroy() {
|
||||||
@@ -667,20 +670,21 @@ class LoaderManagerImpl extends LoaderManager {
|
|||||||
mInactiveLoaders.put(id, info);
|
mInactiveLoaders.put(id, info);
|
||||||
} else {
|
} else {
|
||||||
// We already have an inactive loader for this ID that we are
|
// We already have an inactive loader for this ID that we are
|
||||||
// waiting for! What to do, what to do...
|
// waiting for! Try to cancel; if this returns true then the task is still
|
||||||
if (!info.mStarted) {
|
// running and we have more work to do.
|
||||||
// The current Loader has not been started... we thus
|
if (!info.cancel()) {
|
||||||
// have no reason to keep it around, so bam, slam,
|
// The current Loader has not been started or was successfully canceled,
|
||||||
// thank-you-ma'am.
|
// we thus have no reason to keep it around. Remove it and a new
|
||||||
|
// LoaderInfo will be created below.
|
||||||
if (DEBUG) Log.v(TAG, " Current loader is stopped; replacing");
|
if (DEBUG) Log.v(TAG, " Current loader is stopped; replacing");
|
||||||
mLoaders.put(id, null);
|
mLoaders.put(id, null);
|
||||||
info.destroy();
|
info.destroy();
|
||||||
} else {
|
} else {
|
||||||
// Now we have three active loaders... we'll queue
|
// Now we have three active loaders... we'll queue
|
||||||
// up this request to be processed once one of the other loaders
|
// up this request to be processed once one of the other loaders
|
||||||
// finishes or is canceled.
|
// finishes.
|
||||||
if (DEBUG) Log.v(TAG, " Current loader is running; attempting to cancel");
|
if (DEBUG) Log.v(TAG,
|
||||||
info.cancel();
|
" Current loader is running; configuring pending loader");
|
||||||
if (info.mPendingLoader != null) {
|
if (info.mPendingLoader != null) {
|
||||||
if (DEBUG) Log.v(TAG, " Removing pending loader: " + info.mPendingLoader);
|
if (DEBUG) Log.v(TAG, " Removing pending loader: " + info.mPendingLoader);
|
||||||
info.mPendingLoader.destroy();
|
info.mPendingLoader.destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user