毎分、分単位で関数を実行させるタイマーがあります。アクティビティが一時停止されても、タイマーは引き続き実行されます。不要なので実行したくありません。
一時停止時に実行される場合、どうすれば防止できますか?
メル。
onCreate() で私は持っています
//Respond to clock changing every minute, on the minute
myTimer = new Timer();
GregorianCalendar calCreationDate = new GregorianCalendar();
calCreationDate.add(Calendar.MILLISECOND, (-1*calCreationDate.get(Calendar.MILLISECOND)));
calCreationDate.add(Calendar.SECOND, -1*calCreationDate.get(Calendar.SECOND));
calCreationDate.add(Calendar.MINUTE, 1);
//Update every one minute
myTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
timerMethod();
}
}, calCreationDate.getTime(), 60000);
クラス内 (onCreate() の外側) には次のものがあります。
//Update the clock every minute
protected void timerMethod() {
this.runOnUiThread(Timer_Tick);
} //end TimerMethod
private Runnable Timer_Tick = new Runnable() {
public void run() {
int intTpHour = tpTimePicker.getCurrentHour();
int intTpMinute = tpTimePicker.getCurrentMinute();
displayMyTime(intTpHour, intTpMinute);
}
}; //end Runnable Timer Tick