开发者

How to use a homescreen widget button to shutdown a service?

I have a button whose WidgetProvider kicks off a service with a PendingIntent. That works just fine. How do I similarly attach an event handler to the button so that开发者_如何学Python when it is pressed a second time, it shuts the service down? Is there an appropriate pattern to follow for something like this?

Thanks.


Use a getBroadcast() PendingIntent, where the BroadcastReceiver calls stopService().

Or, use a getService() PendingIntent, where you send a command to your service that has the service call stopSelf().

Or, switch the service to an IntentService, so it shuts down automatically, if that is a better service implementation for your scenario.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜