Reputation: 942
I have it so that when the user pushes the back button it leaves the activity and goes back to the main part of the application. The problem is that I am using a map and when it goes back the GPS is still tracking. How would I get it so that when they leave the map activity the GPS stops tracking?
Upvotes: 2
Views: 858
Reputation: 12367
pressing back button brings user to previous entry in activity stack, and activity he just left receives onPause() callback - this is the best (and only) place to stop everything your activity was doing
Upvotes: 0
Reputation: 38075
If you're using a MyLocationOverlay
on the map, be sure to call disableMyLocation()
in your activity's onPause
(and enable it with enableMyLocation()
in onResume
). See the docs on MyLocationOverlay
.
Upvotes: 1
Reputation: 15267
I have no experience with location services API, but are you finish()
'ing the map activity in your back button code? If yes, you could stop tracking in onDestroy()
, otherwise just before calling the main activity.
Also, if you don't ever want the activities between the main one and the map activity to be remembered in the task stack (that is, you pass through them only "forward"), consider using android:noHistory="true"
in your manifest for them. This way you can avoid overriding back button.
Also see here: android how to stop gps
Upvotes: 0