![](/img/trans.png)
[英]NullPointerException after Closing App with Service still running
[英]LocationUpdatesForegroundService app process is still running after closing app
我正在對Google Play定位服務進行一些調查Google Play定位示例
我正在LocationUpdatesForegroundService示例應用程序上嘗試以下問題:關閉應用程序后,應用程序進程仍在運行。
重現它的步驟:
我的期望是必須停止應用程序進程(及其所有線程),但並非必須如此。
關閉應用程序后,該應用程序進程仍在運行
調用后我關閉應用程序時會發生這種情況
startForeground(NOTIFICATION_ID, getNotification());
如何避免呢?
它看起來與用於收集位置的前台服務有關。 應用關閉時如何停止服務?
根據文檔,該Service
是Android組件,即使該應用已關閉,該組件仍在后台運行。
如果要在從最近的任務中刪除應用程序(例如,應用程序終止)時停止服務,則必須使用AndroidMenifest.xml
android:stopWithTask="true"
來明確關閉該服務。
例子
<service
android:name=".LocationUpdatesForegroundService"
android:stopWithTask="true" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.