如何在偏好更改时重新安排警报管理器

发布于 2024-09-02 17:31:37 字数 512 浏览 4 评论 0原文

我有一个 Android 服务。当手机启动时,广播接收器会收到通知,并安排服务以 X 分钟的间隔重复运行。从此以后,每隔 X 分钟,另一个广播接收器就会收到这些通知并启动该服务,该服务完成其工作并退出。到目前为止,一切都很好。

现在我希望这 X 分钟是可配置的。我有一个类似于下面链接中给出的 perf.xml 。该 XML 捕获了我的所有偏好以及服务计时器的偏好。 http://android- trip.blogspot.com/2010/01/for-almost-any-application-we-need-to.html

现在,当用户更改首选项时;如何重新安排闹钟时间?有没有办法可以设置偏好更改的监听器?我仅使用 XML 文件来指定首选项屏幕。

任何想法都会受到欢迎。

干杯

I have an Android Service. When a phone boots up, a broadcast receiver receives a notification and it schedules the service to run repeatedly at a gap of X minutes. Henceforth After every X minutes another broadcast receiver gets those notifications and kicks the service off, which does it's job and quits. So far so good.

Now I want those X minutes to be configurable. I have a perf.xml similar to what is given at the link below. This XML captures all my preferences along with that of service timer.
http://android-journey.blogspot.com/2010/01/for-almost-any-application-we-need-to.html

Now when user changes preferences; how can I reschedule the alarm? Is there a way I can set a listener on preferences change? I have used only XML files to speficy preferences screen.

Any ideas will be welcome.

Cheers

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

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

发布评论

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

评论(1

心碎的声音 2024-09-09 17:31:37

有OnPreferenceChangeListener只需设置它并实现它。我记得你将其设置为首选项。因此,您需要获取此首选项 findPreference("myAlarmInterval");然后设置侦听器

如果您的服务不使用相同的首选项,这将起作用。根据开发人员文档,它将在以下情况下被调用:
- 已被用户更改
- 即将被设置和/或保留。

因此,新的首选项值尚不可用于您的服务。

There is OnPreferenceChangeListener just set it and implement it. As i remember you set it to the preference. So you need to get this preference findPreference("myAlarmInterval"); and then set the listener

This will work if your service doesn't use the same preference. According to the developer docs it will be called when
- has been changed by the user
- is about to be set and/or persisted.

So, a new preference's value is not yet available to your service.

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