本文介绍了Android的 - 为什么要使用挂起的意图进行geofences的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了教程地理围栏在Android(http://developer.android.com/training/location/geofencing.html)我想知道为什么回调的geofences通过悬而未决的意图进行,而不是一个简单的回调接口。

如果在活动中实现的,人们通常会断开在的onPause的位置客户端()无论如何,所以previously加入geofences不会跟踪任何申请后已暂停/被破坏了,那么为什么挂起的意图是什么?还是我在这里弄错了?

解决方案

这主要是因为geofences的设计,即使不工作,应用程序运行。

我相信你在这里错了。事实上,geofences特别不用于直接触发UI中,如在的文档:

现在,你可能会选择说你只想使用geofences,而你有你在前台活动。但是,你必须删除这些geofences在的onPause()。地理栅栏将继续注册,直到它的到期时间或手动删除,AFAICT。

I just finished the tutorial for geofencing on Android (http://developer.android.com/training/location/geofencing.html) and 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?

解决方案

Mostly because geofences are designed to work even without your application running.

I believe that you are mistaken here. In fact, geofences specifically are not designed for directly triggering UI, as is discussed in the documentation:

Now, you might elect to say that you want to only use geofences while you have your activity in the foreground. However, you would have to remove those geofences in onPause(). A geofence will remain registered until its expiration time or manually removed, AFAICT.

这篇关于Android的 - 为什么要使用挂起的意图进行geofences的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 06:43