I have a service running 开发者_JS百科with a background thread polling for XMPP messages. I want to issue a toast from the Thread. Previous stackoverflow questions have dealt with this by using the runOnUiThread Activity method, however this is not available in a Service. My question is what is the suggested method in a Service? Many thanks in advance
You could try to callbacks similar to the example at http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/RemoteService.html. Specifically see the section starting with the comment
/**
* Our Handler used to execute operations on the main thread. This is used
* to schedule increments of our value.
*/
精彩评论