Pause Location services when app is minimized?

只愿长相守 提交于 2020-01-17 04:35:07

问题


I currently have an application that uses location updates when one of the activities is running. However, I want to pause/stop location services when the user minimizes the application, goes to the home, or moves to another activity until I need the location again. I do not want to stop the app, as there can be some continually running data. I just want to stop the location updates while the app is minimized. Then when the app is reopened, I want to begin the services again. Please and Thank You!


回答1:


Just add the starting and stopping code into the activities onResume and onPause methods.

Without having source code to look at it's hard to give you a detailed answer.

if you're using the android docs here: http://developer.android.com/training/location/retrieve-current.html

the relevant methods would be

mLocationClient.connect();

and

mLocationClient.disconnect();


来源:https://stackoverflow.com/questions/25755990/pause-location-services-when-app-is-minimized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!