开发者

How to reschedule Alarm Manager on Preference Change

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜