1

After a relatively easy coast to simple app coding, I would like to understand better the intricate relationships between various conceptual components in Android.

More specifically, I would like to understand what is Runnable, Looper and Handler.

As you may noticed, the above 3 terms are links to formal documentation in http://developer.android.com so my question may seem strange, so let me explain: That documentation may be perfect for someone who already understands how things work in Android, but I need something that sequentially walks through fundamentals, building on top of previous concepts.

To summarize, I need some sort of tutorial on core inner building blocks of Android. Can you recommend one?

an00b
  • 11,338
  • 13
  • 64
  • 101

2 Answers2

1

The detailed article Painless Threading is probably your best resource for threading on Android.

The moral of the story is that AsyncTask makes multithreading easier for you.

Matthew
  • 44,826
  • 10
  • 98
  • 87
  • OMG you are an angel. There's so much documentation that I can't find the important stuff... I found http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html but it's not as dummy-friendly as Painless Threading. :) – an00b Mar 30 '11 at 19:30
  • There are some really nice articles in there. If you click around on the left pane you can find more as well! – Matthew Mar 30 '11 at 19:31
  • http://stackoverflow.com/questions/5009816/android-cant-create-handler-inside-thread-that-has-not-called-looper-prepare/5009894#5009894 suggests that AsyncTask can't be started from a non-UI thread. Instead, he suggests yet another level of indirection by calling Activity.runOnUiThread() with a Runnable that kicks off your AsyncTask. Whew... – an00b Mar 31 '11 at 01:04
1

Runnable is a core Java interface - it represents a code part that can be run (usually by a specific thread).

Handler is an Android class that is responsible for posting a Runnable\Message so that a particular thread will run or process them (in a specific order).

Looper is the structure that holds the Runnable\Message queue that a HandlerThread will read from.

SirKnigget
  • 3,614
  • 2
  • 28
  • 61