0

I have a problem with my location manager updates. Every time I quit an activity or when I quit the whole app location manager keeps updating location.

I wanted the app to keep updating location when the display is turned off so I used

@Override
protected void onPause() {
    super.onPause();
    if (this.isFinishing()) {
        locationManager.removeUpdates(this);
         }
}

I've put locationManager.removeUpdates(this); even in onBackPressed() method bud after quitting the activity by pressing back or quitting the app the manager is stil requesting updates.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Lowrider
  • 31
  • 1
  • 5

2 Answers2

0

Refer Understanding of isFinishing()
When the user switches to another app, your application is not necessarily killed by the OS until it needs to free up the resources. Hence, isFinishing() may retrun true while onPause() is being called.
Later, when the OS does kill your app, the onPause() is not called as the app is already in background.
Use the onStop() call.

Community
  • 1
  • 1
ranjan_purbey
  • 421
  • 4
  • 11
  • Sadly this didn't work. Somehow when I press back button to go back to main activity the location manager keeps updating location (location icon blinking in notification bar) I've tried to put everywhere locationManager.removeUpdates(this); but it just does not stop updating my location. – Lowrider Dec 28 '16 at 11:36
0

just set "location manager" and "Location updater listener" to NULL :

@Override
protected void onPause() {
super.onPause();
if (this.isFinishing()) {
    locationManager.removeUpdates(this);
     locationManager=null;
     }
}
Hamid Waezi
  • 878
  • 1
  • 7
  • 14