Reputation: 83
beerPref2.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
// TODO Auto-generated method stub
final ListPreference listrefresh = (ListPreference) preference;
final int idx = listrefresh.findIndexOfValue((String) newValue);
if(idx==0){
// set refresh application in each 1 minute according to current time
}
else if(idx==1)
{
// set refresh application in each 10 minute according to current time
}
else if (idx==2)
{
// set refresh application in each 1 hour according to current time
}
else
{
// set refresh application in each 24 hour according to current time
}
return true;
}
});
i have to use this within setting plz tell me how i will apply thread or some thing else so that our application get refreshed in each 1, minute ,10 minute ... accordig to setting in list prefnces plz post me code for that.
Upvotes: 0
Views: 146
Reputation: 7899
I would prefer to use ScheduledExecutorService and then you can define refresh interval in method arguments like below.
ExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(RunableTask, initialDelay, delay , TimeUnit.MINUTES);
//where delay is refresh interval and you can set initialDelay as 0;
Pass TimeUnit in minutes and then take a variable delay which takes value from setting .
Upvotes: 2