The amount of words you abuse is incomprehensible. runOnUiThread is a helper method for running code in a MAIN thread. Typically, this method is used when trying to update the user interface from a workflow. Since a Service does not have a user interface, runOnMainThread seems quite inappropriate.
You should rephrase one of the following questions:
- How to run my off-MainThread code?
Use AsyncTask or IntentService .
- How to execute code on MainThread when I am now in a different thread. (Which is commonly used in
Activity runOnUiThread .)
Create a Handler on your Service its MainThread and send a Runnables message to it / send messages to it.
source share