问题
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