Friday, April 10, 2015

Painless threading

Main or UI thread:
- in charge of dispatching the events to the appropriate widgets & drawing event.
- ANR happens if UI thread blocked for more than 5 secs.
- the Android UI toolkit is not thread-safe and must always be manipulated on the UI thread.

ways to access the UI thread from other threads
- Activity.runOnUiThread(Runnable)
- View.post(Runnable)
- View.postDelayed(Runnable, long)
- Handler

These methods tend to make your code complicated. Android offers a new utility class, called AsyncTask, that simplifies the creation of long-running tasks that need to communicate with the user interface.

0 comments:

Post a Comment