/** * State for a result that is pending for a broadcast receiver. Returned * by {@link BroadcastReceiver#goAsync() goAsync()} * while in {@link BroadcastReceiver#onReceive BroadcastReceiver.onReceive()}. * This allows you to return from onReceive() without having the broadcast * terminate; you must call {@link #finish()} once you are done with the * broadcast. This allows you to process the broadcast off of the main * thread of your app. * * <p>Note on threading: the state inside of this class is not itself * thread-safe, however you can use it from any thread if you properly * sure that you do not have races. Typically this means you will hand * the entire object to another thread, which will be solely responsible * for setting any results and finally calling {@link #finish()}. */ publicstaticclassPendingResult { ... /** * This can be called by an application in {@link #onReceive} to allow * it to keep the broadcast active after returning from that function. * This does <em>not</em> change the expectation of being relatively * responsive to the broadcast (finishing it within 10s), but does allow * the implementation to move work related to it over to another thread * to avoid glitching the main UI thread due to disk IO. * * @return Returns a {@link PendingResult} representing the result of * the active broadcast. The BroadcastRecord itself is no longer active; * all data and other interaction must go through {@link PendingResult} * APIs. The {@link PendingResult#finish PendingResult.finish()} method * must be called once processing of the broadcast is done. */ publicfinal PendingResult goAsync() { PendingResultres= mPendingResult; mPendingResult = null; return res; }