I would like to use GPS in my application but in some specific way. I want to use it only when the user does something with the app, but when the app goes to sleep then the GPS should stop doing things. I wonder how to manage this in way in which I wouldn’t have to manage gps in all activities but only in one class or something similar.
Share
If the GPS is used only in one Activity
Turn off the GPS when the Activity’s
onPause()method is called.If your GPS is running in service you will have to have the service know if your app is running or not, what you can do is make a static boolean in the Service and every time any Activity’s
onResume()method is called, set the Service’s boolean to true. Every time an Activity pauses, set the boolean to false.