Methods Summary |
---|
public static void | add(java.lang.Runnable finisher)Add a runnable to finish (or wait for) a deferred operation
started in this context earlier. Typically finished by e.g.
an Activity#onPause. Used by SharedPreferences$Editor#startCommit().
Note that this doesn't actually start it running. This is just
a scratch set for callers doing async work to keep updated with
what's in-flight. In the common case, caller code
(e.g. SharedPreferences) will pretty quickly call remove()
after an add(). The only time these Runnables are run is from
waitToFinish(), below.
sPendingWorkFinishers.add(finisher);
|
public static boolean | hasPendingWork()Returns true if there is pending work to be done. Note that the
result is out of data as soon as you receive it, so be careful how you
use it.
return !sPendingWorkFinishers.isEmpty();
|
public static void | remove(java.lang.Runnable finisher)
sPendingWorkFinishers.remove(finisher);
|
public static java.util.concurrent.ExecutorService | singleThreadExecutor()Returns a single-thread Executor shared by the entire process,
creating it if necessary. // lazy, guarded by class
synchronized (QueuedWork.class) {
if (sSingleThreadExecutor == null) {
// TODO: can we give this single thread a thread name?
sSingleThreadExecutor = Executors.newSingleThreadExecutor();
}
return sSingleThreadExecutor;
}
|
public static void | waitToFinish()Finishes or waits for async operations to complete.
(e.g. SharedPreferences$Editor#startCommit writes)
Is called from the Activity base class's onPause(), after
BroadcastReceiver's onReceive, after Service command handling,
etc. (so async work is never lost)
Runnable toFinish;
while ((toFinish = sPendingWorkFinishers.poll()) != null) {
toFinish.run();
}
|