简体   繁体   中英

Back button android-sdk?

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?

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 .

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

按下返回按钮将用户带到活动堆栈中的上一个条目,而他刚刚离开的活动将接收onPause()回调-这是停止活动正在执行的所有操作的最佳(也是唯一)位置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM