微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android – 为什么要使用挂起意图进行地理围栏

我刚刚在 Android( http://developer.android.com/training/location/geofencing.html)上完成了地理围栏的教程,我想知道为什么地理围栏的’回调’是通过挂起的意图而不是简单的回调接口完成的.

如果在一个活动中实现,通常会在onPause()中断开位置客户端,因此在应用程序暂停/被销毁后,以前添加的地理围栏也不会被跟踪,那么为什么一个未决的意图呢?或者我错了?

解决方法

I wonder why the ‘callback’ for geofences are done via pending intents and not a simple callback interface.

主要是因为地理围栏设计为即使没有运行应用程序也可以工作.

If implemented in an activity,one would usually disconnect the location client in onPause() anyway,so prevIoUsly added geofences would not be tracked either after the application paused/was destroyed,so why a pending intent? Or am I mistaken here?

我相信你错了.实际上,地理围栏专门不是为直接触发UI而设计的,如the documentation中所述:

The Intent sent from Location Services can trigger varIoUs actions in your app,but you should not have it start an activity or fragment,because components should only become visible in response to a user action.

现在,您可以选择说您只想在前台活动时使用地理围栏.但是,您必须在onPause()中删除这些地理围栏.地理围栏将在到期时间之前保持注册状态或手动删除,AFAICT.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐