Consulting Training Blog Careers About Us Contact Us

White Paper: Android Non-UI to UI Thread Communications

On the Android platform, applications operate, by default, on one thread. This thread is called the UI thread. It is often called that because this single thread displays the user interface and listens for events that occur when the user interacts with the app. 

Developers quickly learn that if code running on that thread hogs that single thread and prevents user interaction (for more than 5 seconds), it causes Android to throw up the infamous Android Not Responsive (ANR) error.

So how do you prevent ANR? Your application must create other threads and put long running work on non-UI threads.

MANY NON-UI TO UI THREAD COMMUNICATION OPTIONS

Well, as it turns out, there are several ways to have non-UI threads request updates to the UI through the UI thread. In fact, I plan to show you five ways to have the non-UI thread send UI update requests to be executed on the UI thread.

  1. Use runOnUiThread( ) method call
  2. Use post( ) method call
  3. Use the Handler framework
  4. Use a Broadcasts and BroadcastReceiver (optionally with LocalBroadcastManager)
  5. Use an AsyncTask’s onProgressUpdate( ) method

As with all options, there are considerations when making a selection from this list. Much depends on your design decisions about how/where the non-UI thread is created and launched. This white paper walks through all five options and considerations you'll need to know.

Download Now

Please complete the following form to receive your White Paper: Android Non-UI to UI Thread Communications via email. Intertech will not share any of your information with third parties.