// [... Perform background processing task, update myProgress ...] PublishProgress(myProgress)
// [... Continue performing background processing task ...]
// Return the value to be passed to onPostExecute return result;
As shown in Listing 9-9, your subclass should implement the following event handlers:
> doinBackground Takes a set of parameters of the type defined in your class implementation. This method will be executed on the background thread, so it must not attempt to interact with UI objects.
Place your long-running code here, using the publishProgress method to allow onProgressUpdate to post progress updates to the UI.
When your background task is complete, return the final result for the onPostExecute handler to report it to the UI.
> onProgressUpdate Override this handler to post interim updates to the UI thread. This handler receives the set of parameters passed in to publishProgress from within doinBackground.
This handler is synchronized with the GUI thread when executed, so you can safely modify UI elements.
> onPostExecute When doinBackground has completed, the return value from that method is passed in to this event handler.
Use this handler to update the UI once your asynchronous task has completed. This handler is synchronized with the GUI thread when executed, so you can safely modify UI elements.
Was this article helpful?
Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.