5
A
回答
2
你應該可以調用stopSelf();
http://developer.android.com/reference/android/app/Service.html#stopSelf()
+0
是的,但你會如何告訴該服務調用'stopSelf'?該消息將排隊 – binnyb
3
bevor消息到服務排隊onStartCommand被調用。它將消息轉發給排隊。所以你可以只覆蓋onStartCommand,這樣的事情:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent.getAction().equals("Stop"))
stopSelf();
onStart(intent, startId);
return START_NOT_STICKY;
}
歡呼
1
目前我偶然發現了這requierement爲應用我的工作。我將嘗試使用onStartCommand向Intent Service發送消息以停止工作(例如,設置布爾標誌stopWork = true),並在工作作業期間或下一個排隊的任務之前對其進行評估。 IntentService不會立即停止,但會跳過所有未完成的任務。希望能幫助到你。也可以自己嘗試一下。
相關問題
- 1. IntentService立即停止
- 2. 如何停止IntentService
- 3. 如何停止IntentService?
- 4. Android停止指定IntentService
- 5. 從活動中停止IntentService
- 6. 停止IntentService只能有效
- 7. 如何在運行SensorListener時停止IntentService
- 8. 當IntentService停止時處理或收聽
- 9. 停止IntentService的正確方法
- 10. AlarmManager和IntentService最終停止工作
- 11. 如何在android中停止intentservice?
- 12. 來自IntentService的停止活動
- 13. 當IntentService暫停
- 14. 如何停止一個IntentService同時有很多IntentService正在運行
- 15. 如何停止Android系統從重新傳遞舊意向IntentService?
- 16. 當沒有斷點時,無限IntentService停止工作
- 17. 停止/清除互聯網關閉時的IntentService隊列?
- 18. 的Android停止IntentService不接近傳感器
- 19. Android IntentService調用不會自行停止的烤麪包
- 20. intentService不會被System終止?
- 21. IntentService防止活動破壞
- 22. Android FusedLocationApi.requestLocation在後臺更新:停止應用程序終止時的IntentService
- 23. 如何創建永無止境的IntentService?
- 24. iPhone CoreAudio停止時停止
- 25. 停止按鈕不停止?
- 26. 如何將android服務置於前臺或防止其自動停止,否則無需使用intentservice?
- 27. GCM IntentService
- 28. Android IntentService
- 29. IntentService android.os.NetworkOnMainThreadException
- 30. 停止或懸停
'stopService(intent);'? – binnyb