[英]LocationUpdatesForegroundService app process is still running after closing app
I am doing some investigation on Google Play Location Service Google Play Location Samples 我正在对Google Play定位服务进行一些调查Google Play定位示例
I am experiment the following issue on LocationUpdatesForegroundService sample application: the app process is still running after closing the app. 我正在LocationUpdatesForegroundService示例应用程序上尝试以下问题:关闭应用程序后,应用程序进程仍在运行。
Steps to reproduce it: 重现它的步骤:
My expectation is that the app process (and all its threads) has to be stopped but it does not. 我的期望是必须停止应用程序进程(及其所有线程),但并非必须如此。
The app process is still running after closing the app 关闭应用程序后,该应用程序进程仍在运行
It happens when I close the app after calling 调用后我关闭应用程序时会发生这种情况
startForeground(NOTIFICATION_ID, getNotification());
How can avoid it? 如何避免呢?
It looks related with the foreground service for collecting location. 它看起来与用于收集位置的前台服务有关。 How can I stop the service while the app is closing?
应用关闭时如何停止服务?
As per the documentation the Service
is the Android component which run continues in background even if the app is closed. 根据文档,该
Service
是Android组件,即使该应用已关闭,该组件仍在后台运行。
If you want to stop service when app is remove from recent task(ie app kill) you have to used android:stopWithTask="true"
in AndroidMenifest.xml
for explicitly closed the service. 如果要在从最近的任务中删除应用程序(例如,应用程序终止)时停止服务,则必须使用
AndroidMenifest.xml
android:stopWithTask="true"
来明确关闭该服务。
Example , 例子
<service
android:name=".LocationUpdatesForegroundService"
android:stopWithTask="true" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.