I have a method in my service witch must be called from within a thread but I don't want that code to execute in the thread.
How can I call runOnUiThread if I have no activity and I am calling it from a service?
Thanks.
I am not interested in AsyncTask solution!
Maybe a Handler
can help you. Handler is an element associated to the thread where is created, you can post a runnable with your code to the Handler and that runnable will be executed in the thread where the Handler was created.
Information link: http://developer.android.com/reference/android/os/Handler.html
The amount of words you are misusing is baffling. runOnUiThread
is a helper-method to run code on the MAIN-thread. Normally, you use this method when you try to update your UI from a working thread. Since a Service
doens't have a UI, runOnMainThread would seem highly inappropriate.
You question should be rephrased to either of the following:
Use an AsyncTask
or an IntentService
.
Activity
runOnUiThread
can be used.)Create a Handler
on your Service
his MainThread and post Runnables
on it / send messages to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With