0
我想在我的服務中重新啓動我的TimerTask,當時我在配置Activity中更改了刷新時間。在服務中重新啓動TimerTask的最佳方式
的配置活動改變了公共靜態更新週期長
你有我的一些想法?
public void onStart(Intent intent, int startId) {
// init the service here
try {
if (prefs.getString("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);
}
到目前爲止感謝。 Stefan
我試過這個,但它只需要在第一次設置的UPDATE_INTERVAL的值=/ – Stefan
而不是使用scheduleAtFixedRate(),你應該只使用schedule(),並遞歸地調用函數,以便它會創建一個新計時器每次迭代更新的時間間隔。 –