使用 PassiveProvider 和 PendingIntents 确保应用程序位置的“新鲜度”
我正在阅读 Reto Meier 的(非常有用)Android 开发者博客文章 深入了解位置 当我读到以下关于使用 PassiveProvider 和 PendingIntents 来帮助维护的句子时一个“新鲜”应用程序:
“如果您的应用程序识别“退出”的概念(通常当用户单击主屏幕上的后退按钮时),那么关闭被动位置更新是一种很好的方式 - 包括禁用被动清单接收器。”
虽然我理解应用程序需要成为 Android 社区中的“好公民”,但这是否也违背了使用 PassiveProvider 和 PendingIntents 来帮助确保位置新鲜度的目的?据我了解,关闭被动位置更新将阻止我的应用程序接收这些更新。如果是这种情况,那么当用户重新启动我的应用程序时,他们是否需要等待另一个位置修复?我知道我可以调用 getLastLocation(),但我只是想知道当您在应用程序退出时显式关闭 PassiveProvider 和 PendingIntents 时,它们如何帮助确保新鲜度。
I was reading Reto Meier's (very useful) Android developer blog post A Deep Dive into Location when I read the following sentence concerning use use of the PassiveProvider and PendingIntents to help maintain a "fresh" application:
"If your app recognizes the concept of “exiting” (typically when the user clicks the back button on your home screen), it’s good form to turn off passive location updates - including disabling your passive manifest Receiver."
While I understand the need for apps to be "good citizens" in the Android community, doesn't this also defeat the purpose of using the PassiveProvider and PendingIntents to help ensure location freshness? From what I understand, turning off the passive location updates will prevent my app from receiving those updates. If this is the case, then when the user re-launches my app, wont they have to wait for another location fix? I know that I can call getLastLocation(), but I was just wondering how the PassiveProvider and PendingIntents help to ensure freshness when you explicitly turn them off when the app exits.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想答案不是那么明显:
没有真正的方法可以关闭 Android 中的应用程序(我的意思是对于用户)。但该博客似乎假设在主应用程序屏幕/活动中点击后退按钮实际上意味着退出应用程序。例如,这就是海豚对后退按钮按下的反应方式。
因此,如果人们使用此按钮,您可以假设他们想要退出您的应用程序,您可以关闭您使用的所有资源,包括被动位置提供程序和应用程序。接收器。
但是,大多数情况下,人们只需点击菜单按钮,然后通过这种方式从一个应用程序切换到另一个应用程序,然后让它们全部打开。在这种情况下,请让您的接收器就位,以便您的应用程序保持最新状态,正如 Reto 在他的帖子中所解释的那样。
更新:以这种方式使用后退按钮(关闭应用程序)看起来是一个官方的好习惯,这个博客对此非常有趣:http://www.androiduipatterns.com/2011/03/back-button-behavior.html。
问候,
史蒂芬
Well, I guess the answer is not so obvious :
there is no real way to close an application in android (for the user I mean). But the blog seems to assume that hitting the back button while in the main app screen/activity actually means to exit the app. This is, for instance, the way dolphin reacts to a back button hit.
So if people use this button, you can assume they want to quit your app and you can just close every resource you used, including passive location providers & receivers.
But, mostly, people will just hit the menu button and switch from an app to the other this way and let them all open. In this case, let your receivers in place so that your app keeps fresh as explained by Reto in his post.
Update : it looks like an official good practice to use back button this way (close app), this blog is quite interesting about it : http://www.androiduipatterns.com/2011/03/back-button-behavior.html.
Regards,
Stéphane