I have a service that look gps coordinate. I want that when the user click on the home button the gps stop to work (battery saving).
The strategy i am using is this:
@Override
public void onPause() {
super.onPause();
doUnbindService();
}
@Override
public void onResume() {
super.onResume();
doBindService();
}
on each Activity that use the service. The problem is that each time i switch activity it stop and resume. Is there a strategy that let me have the service always up until my app is in foregroung?
I have an app with 3 activities that use a service to deal with the GPS. In each activity’s onStart() I have code of the form
and in each onStop() I have
You should find that activity 2’s onStart() will execute before activity 1’s onStop(). Thus only when no activities are running will the service stop.