Sunday, February 23, 2014

Runnable in background thread

In this exercise, we need to check if the current thread is the main thread, or called UI thread. Using the code:Looper.getMainLooper().getThread()==Thread.currentThread()

If it's true, means it's in main thread, otherwise it's in background thread.

The example show how to implement a Thread with Runnable object. And call its start() method to starts the new Thread of execution. Also notice that if you call its run() method, it will calls the run() method of the Runnable object directly, in current thread.