Android:接近警报
我已按照本教程了解如何使用接近度警报以及如何注册它。 这一切都有效,但是当我关闭应用程序(使用后退按钮,而不是主页按钮)时,接近警报不再起作用。有谁知道如何设置它以使其在后台运行? 提前致谢!
I have followed this tutorial about how to use the proximity alert and how to register it.
It all works but when I close the app (with the back button, not the home-button) then the proximity alert does not work anymore. Does anyone know how to set it so that it runs in the background?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您的应用程序未运行时,您似乎无法获取位置更新。在后台接收位置更新不是一个好主意,因为它会耗尽电池电量,并且用户可能不知道位置正在被跟踪,因为按应用程序上的后退按钮的正常行为是关闭所有服务。如果我希望我的应用程序继续在后台运行,我作为用户会按主页按钮。
查看“我的足迹”应用程序使用的模型。
另请参阅 Android 有关位置和使用模型的文档:
http://developer.android.com/guide/topics/location /obtaining-user-location.html
如果您已经了解了不让应用程序在后台执行此操作但仍希望在后台运行的原因,请查看服务
http://developer.android.com/reference/android/app/Service.html
它们可以在后台运行,并在需要时为您的应用程序提供数据。
It seems that you can not get location updates when your application is not running. Receiving location updates in the background is not a good idea since it drains battery power and the user might not be aware that the location is being tracked since the normal behavior for pressing the back button on the application is for it to close all services. If I want my application to continue running in the background, I as a user would press the home button.
Look at the model used by the "My Tracks" application.
Also see the documentation from Android on locations and usage models:
http://developer.android.com/guide/topics/location/obtaining-user-location.html
If you have informed yourself about the reasons not to have the application do this in the background but still want to run this in the background, look into Services
http://developer.android.com/reference/android/app/Service.html
They can run in the background and provide your application with data when asked.
Android 的基本部分...服务。
http://developer.android.com/guide/topics/fundamentals/services.html
Fundamental part of Android... Services.
http://developer.android.com/guide/topics/fundamentals/services.html
如果您注册了它,您应该会收到它,但请记住,如果您的屏幕关闭,接近警报可能不会立即发出。如果您的屏幕关闭,则每 4 分钟探测一次位置,如 文档。
You should get it if you register for it, but keep in mind that proximity alert may not be immediate if your screen is off. If your screen is off, then location is probed for every 4 minutes as stated in the documentation.