Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top