简体   繁体   English

离开应用后,Android Google Play定位服务会继续

[英]Android Google Play Location Services continue after leaving app

I am using Google Play Services in my app so that I can make use of the Location features. 我在我的应用中使用Google Play Services ,以便我可以使用Location功能。 I have read the docs, but it isn't clear what happens when I am running location updates and I leave the app. 我已经阅读了文档,但目前尚不清楚当我运行位置更新并离开应用程序时会发生什么。

Do location updates still occur in the background? 位置更新是否仍然在后台进行? If not, how do I do this? 如果没有,我该怎么做?

Do location updates still occur in the background? 位置更新是否仍然在后台进行? If not, how do I do this? 如果没有,我该怎么做?

What I did for my app was to continue to track the location with a service in the background. 我为我的应用程序做的是继续在后台跟踪服务的位置。 In addition, you may want to start and mark the service as Foreground so that user will be shown a notification that you are tracking the phone's location. 此外,您可能希望启动该服务并将其标记为Foreground,以便向用户显示您正在跟踪手机位置的通知。

Make sure you remove the LocationListener when you leave your app, usually I put it in onPause() method of the Activity , otherwise, it's up to you to handle whether you should do it. 当你离开你的应用程序时,请确保删除LocationListener ,通常我将它放在Activity onPause()方法中,否则,由你决定是否应该这样做。 Here is the example code: 这是示例代码:

@Override   
protected void onPause() {      
locationMananger.removeUpdates(this);       
// with "this" is your Activity implementing the LocationListener       
super.onPause();    
}

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM