返回按钮 android-sdk?
我拥有它,以便当用户按下后退按钮时,它会离开活动并返回到应用程序的主要部分。问题是我正在使用地图,当它返回时 GPS 仍在跟踪。我该如何获取它,以便当他们离开地图活动时 GPS 停止跟踪?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在地图上使用
MyLocationOverlay
,请务必在 Activity 的onPause
中调用disableMyLocation()
(并使用>onResume
中的 >enableMyLocation())。请参阅 < 上的文档代码>MyLocationOverlay。If you're using a
MyLocationOverlay
on the map, be sure to calldisableMyLocation()
in your activity'sonPause
(and enable it withenableMyLocation()
inonResume
). See the docs onMyLocationOverlay
.我没有使用位置服务 API 的经验,但是您是否在后退按钮代码中
finish()
处理地图活动?如果是,您可以在onDestroy()
中停止跟踪,否则就在调用主活动之前停止跟踪。另外,如果您不希望在任务堆栈中记住主活动和地图活动之间的活动(也就是说,您仅“向前”传递它们),请考虑使用
android:noHistory=" true”
在您的清单中。这样您就可以避免覆盖后退按钮。另请参阅此处:android 如何停止 gps
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 inonDestroy()
, 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() 回调 - 这是最好的(也是唯一的)
停止您正在进行的所有活动的地方
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