gpt4 book ai didi

Android - 为什么对地理围栏使用未决 Intent

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:11:56 24 4
gpt4 key购买 nike

我刚刚完成了 Android 上的地理围栏教程 (http://developer.android.com/training/location/geofencing.html),我想知道为什么地理围栏的“回调”是通过未决 Intent 而不是简单的回调接口(interface)完成的。

如果在 Activity 中实现,通常会在 onPause() 中断开位置客户端,因此在应用程序暂停/被销毁后也不会跟踪先前添加的地理围栏,所以为什么要挂起 Intent ?还是我弄错了?

最佳答案

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.

现在,您可能会选择说,当您在前台进行 Activity 时,您只想使用地理围栏。但是,您必须在 onPause() 中删除这些地理围栏。地理围栏将保持注册状态,直到其到期时间或手动删除,AFAICT。

关于Android - 为什么对地理围栏使用未决 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16630926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com