内容提供商更改时启动应用程序

发布于 2024-09-04 05:41:41 字数 204 浏览 3 评论 0原文

我希望我的应用程序在有人修改内容提供程序时启动。一个具体的设置。当设置值时,设置框架会调用“通知”。

如果我的应用程序启动了,我想我会使用 registerContentObserver() ,但它没有启动。

可以在我的清单中定义一些唤醒我的应用程序的意图过滤器。备用计划是让一个注册了侦听器的服务一直运行,但这似乎是一种浪费或资源。

谢谢,奥拉

I want my application to start when someone modifies a content provider. A setting to be specific. The settings framework calls "notify" when a value is set.

If my app was started I would use registerContentObserver() I guess, but is is not started.

Can define some intent-filter in my manifest that wakes up my application. A back up plan would be to have a service running all the time that has registered a listener, but that seems like a wast or resources.

Thanks, Ola

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当梦初醒 2024-09-11 05:41:41

Android 设备不直接支持此功能,因为每次 ContentProvider 的数据更改时启动应用程序都会真正耗尽电池电量。要进行查询,您需要在服务中进行,正如您所说,这是可以理解的不可取的。

其次,启动意图是一个用户操作。 Android 确实不支持允许应用程序在没有用户请求的情况下自行启动...这样做是不礼貌的!如果您的用户正在做一些重要的事情,然后您的应用程序弹出在顶部怎么办?请记住,控制权是用户,而不是您。不要启动应用程序,而是考虑放置一个状态栏通知,以便用户可以在方便的时候进行处理。

This isn't directly supported by the Android device because starting an app every time a ContentProvider's data changes is a path to really killing your battery. To do the query, you'd need to do it in a service, which as you said is understandably undesirable.

Secondly, starting an intent is a user action. Android really doesn't support allowing an application to start all on its own without user request... Doing so would be impolite! What if your user was doing something important and then your app pops up on top? Remember the user is in control, not you. Instead of starting an application, consider placing a Status Bar Notification so the user can deal with it when it's convenient for them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文