[英]How to use a homescreen widget button to shutdown a service?
我有一個按鈕,其WidgetProvider通過PendingIntent啟動服務。 那很好。 我如何類似地將事件處理程序附加到按鈕,以便在再次按下按鈕時將其關閉服務? 是否有適當的模式可以遵循這樣的事情?
謝謝。
使用getBroadcast()
PendingIntent
,其中BroadcastReceiver
調用stopService()
。
或者,使用getService()
PendingIntent
,在其中向具有服務調用stopSelf()
的服務發送命令。
或者,將服務切換到IntentService
,如果對您的方案而言這是更好的服務實現,則它將自動關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.