In an android service I have created thread(s) for doing some background task.
I have a situation where a thread needs to post certain task on main thread\'s message
One method I can think of is this:
1) Let the UI bind to the service.
2) Expose a method like the one below by the Binder that registers your Handler:
public void registerHandler(Handler handler) {
mHandler = handler;
}
3) In the UI thread, call the above method after binding to the service:
mBinder.registerHandler(new Handler());
4) Use the handler in the Service's thread to post your task:
mHandler.post(runnable);