如何重新安排报警管理上preference变化preference

由网友(★你說你愛她﹑納硪呢~﹌)分享简介:我有一个Android服务。当手机启动时,广播接收器接收通知,并将其调度服务,以在X分钟的间隔反复运行。此后每隔X分钟后,另一广播接收器获得这些通知和踢服务关闭,这确实是工作,并退出。到目前为止好。I have an Android Service. When a phone boots up, a broadcas...

我有一个Android服务。当手机启动时,广播接收器接收通知,并将其调度服务,以在X分钟的间隔反复运行。此后每隔X分钟后,另一广播接收器获得这些通知和踢服务关闭,这确实是工作,并退出。到目前为止好。

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.

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

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

现在,当用户改变preferences;我怎样才能重新安排报警?有没有一种方法,我可以设置preferences一个监听器改变?我只用XML文件来speficy preferences屏幕。

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.

任何想法将受到欢迎。

干杯

推荐答案

有是在preferenceChangeListener只需设置它,实现它。我记得你把它设置为preference。所以,你需要得到这个preference找到preference(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

这将工作,如果你的服务不使用相同的preference。据开发者文档它会被调用的时候 - 已被用户修改 - 将要被设置和/或持续

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.

于是,一个新的preference的价值还没有提供给你的服务。

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

阅读全文

相关推荐

最新文章