Android Handlers - inter-thread communication
Here is good post explaining threads and communication using handlers. Also, the same blog has a number of posts regarding various thread constructs in Android
To overcome the problem of getting a Handler for the Thread you just created (but which may not have initialized yet), see How to create a Looper thread, then send it a message immediately?
Call Looper.prepare()
in the new thread, and Looper will be created for you for that thread. Then you can create a Handler to pass back to the other thread.
That is, after calling Looper.prepare()
, the statement Handler h = new Handler()
will create a Handler on the Looper of your new thread.
http://developer.android.com/reference/android/os/Looper.html