i would like to restart my TimerTask in my Service when i changed the refresh time in the config Activity.
The config Activity changes the public static long UPDATE_INTERVAL
Have you some ideas for me?
public void onStart(Intent intent, int startId) {
// init the service here
try {
if (prefs.getStr开发者_JS百科ing("oauth_token_secret", null) != null) {
_startService();
}
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
private void _startService() {
timer.scheduleAtFixedRate(
new TimerTask() {
public void run() {
//doing things
}
}, 0, UPDATE_INTERVAL);
}
Thanks so far. Stefan
Not sure what you mean by "The config Activity changes the public static long UPDATE_INTERVAL", but you can update the interval timing in your run code and it will take effect the next time the TimerTask is run. Or if your Activity is in a seperate class you can create a setter for UPDATE_INTERVAL and when an action is triggered in the Activity you set the timing interval that way.
精彩评论