Android Threads Communication

by keen
  • Android Non-UI to UI Thread Communications (Part 1 of 5)

    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...

  • Android Non-UI to UI Thread Communications (Part 2 of 5)

    Non-UI threads are not allowed to make updates to the UI. Trying to do too much work (as defined as not allowing the user to interact with the UI for more than 5 seconds) on the UI thread leads to ANR errors...

  • Android Non-UI to UI Thread Communications (Part 3 of 5)

    Android threads, in particular the UI thread, have a message queue. Messages in the queue are processed by the thread in order of arrival. In the case of the UI thread, user events (like a button push) cause event messages to be placed in the queue. As explained in the previous posts, the runOnUiThread() and post() methods use this queue under the covers. However, you can use the message queue more directly...

  • Android Non-UI to UI Thread Communications (Part 4 of 5)

    As background for those jumping into the middle of this series, non user interface (UI) threads are not allowed to make updates to the UI. For example, using a non-UI thread to update a TextView’s displayed text results in a CalledFromWrongThreadException. However, trying to do too much work (as defined as not allowing the user to interact with the UI for more than 5 seconds) on the UI thread leads to Android Not Responsive errors...

  • Android Non-UI to UI Thread Communications (Part 5 of 5)

    As you have learned in this series, new threads to perform longer running work is the way to build applications and to avoid Android Not Responsive popups, but if those non-UI threads try to update UI components (like putting new String data in a TextView widget) they trigger a CalledFromWrongThreadException. Previous posts have used the Activity’s runOnUiThread() method, a View’s post() method, the Handler Framework, and Broadcast/BroadcastReceiver components to handle non-UI to UI thread communications. In this last post, my favorite option – the AsyncTask – is explored...