Toast in a self running service

后端 未结 1 575
走了就别回头了
走了就别回头了 2021-01-17 04:14

I have an android activity which runs a remote service and then quits. The service itself, polls on a device node, and checks for changes, I want to use toast to alert the u

相关标签:
1条回答
  • 2021-01-17 04:41

    You can't call a Toast message from the Service. You can't do anything with the UI except from the UI thread. You're going to need to research one of the many ways to communicate with your UI thread from your service - BroadcastReciever, Messenger, AIDL, etc.

    For what you're trying to do, you probably don't need to go as far as the AIDL route. Check out this example the Messenger implementation and then check out the complete example from the sdk-samples:

    http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/MessengerService.html

    0 讨论(0)
提交回复
热议问题