diff options
| author | Dianne Hackborn <hackbod@google.com> | 2013-03-14 19:10:04 -0700 |
|---|---|---|
| committer | Dianne Hackborn <hackbod@google.com> | 2013-03-14 19:17:00 -0700 |
| commit | ca614f78bed7eebf9dbfd77ba5720a0b5eeed816 (patch) | |
| tree | f25d4cb8109f0b35336913427da38c3d3dcaa4aa /core/java/android/content/Loader.java | |
| parent | 5d122d96a5bf3bbaccaca2765b45716efe7ee2ef (diff) | |
Fix a bug where we could lose a loader content change.
If AsyncTaskLoader starts a background update due to a
content change, and that update is cancelled, we drop the
data when it finally arrives and forget that the content changed.
If we later come back to the loader, we then end up showing
stale data because we don't know that we still need to update
due to the old content change.
This change adds a couple new APIs to Loader to deal with the
time between when you ask for whether there is a content change
and finally either commit the data or cancel the update.
AsyncTaskLoader is changed to make use of this so that it doesn't
lose changes.
Change-Id: I3866236b1c22bb9138f2d9f6032b126aeaee2e6e
Diffstat (limited to 'core/java/android/content/Loader.java')
| -rw-r--r-- | core/java/android/content/Loader.java | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/core/java/android/content/Loader.java b/core/java/android/content/Loader.java index 30524148d689..911e49ca604e 100644 --- a/core/java/android/content/Loader.java +++ b/core/java/android/content/Loader.java @@ -58,6 +58,7 @@ public class Loader<D> { boolean mAbandoned = false; boolean mReset = true; boolean mContentChanged = false; + boolean mProcessingChange = false; /** * An implementation of a ContentObserver that takes care of connecting @@ -439,6 +440,7 @@ public class Loader<D> { mStarted = false; mAbandoned = false; mContentChanged = false; + mProcessingChange = false; } /** @@ -458,9 +460,34 @@ public class Loader<D> { public boolean takeContentChanged() { boolean res = mContentChanged; mContentChanged = false; + mProcessingChange |= res; return res; } - + + /** + * Commit that you have actually fully processed a content change that + * was returned by {@link #takeContentChanged}. This is for use with + * {@link #rollbackContentChanged()} to handle situations where a load + * is cancelled. Call this when you have completely processed a load + * without it being cancelled. + */ + public void commitContentChanged() { + mProcessingChange = false; + } + + /** + * Report that you have abandoned the processing of a content change that + * was returned by {@link #takeContentChanged()} and would like to rollback + * to the state where there is again a pending content change. This is + * to handle the case where a data load due to a content change has been + * canceled before its data was delivered back to the loader. + */ + public void rollbackContentChanged() { + if (mProcessingChange) { + mContentChanged = true; + } + } + /** * Called when {@link ForceLoadContentObserver} detects a change. The * default implementation checks to see if the loader is currently started; @@ -512,9 +539,14 @@ public class Loader<D> { public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { writer.print(prefix); writer.print("mId="); writer.print(mId); writer.print(" mListener="); writer.println(mListener); - writer.print(prefix); writer.print("mStarted="); writer.print(mStarted); - writer.print(" mContentChanged="); writer.print(mContentChanged); - writer.print(" mAbandoned="); writer.print(mAbandoned); - writer.print(" mReset="); writer.println(mReset); + if (mStarted || mContentChanged || mProcessingChange) { + writer.print(prefix); writer.print("mStarted="); writer.print(mStarted); + writer.print(" mContentChanged="); writer.print(mContentChanged); + writer.print(" mProcessingChange="); writer.println(mProcessingChange); + } + if (mAbandoned || mReset) { + writer.print(prefix); writer.print("mAbandoned="); writer.print(mAbandoned); + writer.print(" mReset="); writer.println(mReset); + } } }
\ No newline at end of file |
