5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Timerは一回cancelすると、再利用できない

Last updated at Posted at 2012-03-16

Androidで使用しているTimerは一度キャンセルしてしまうと再利用できない。
まあ、常識かもしれないけど。

#NGなコード
Timer mTimer = new Timer(true);
mTimer.schedule(checkTimetask, checkInterval, checkInterval);

mTimer.cancel();
mtimer..schedule(checkTimetask, checkInterval, checkInterval); //→ここでException発生する

#直したコード
mTimer.cancel();
Timer mTimer = new Timer(true);//再度newしないと駄目。
mtimer..schedule(checkTimetask, checkInterval, checkInterval);

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?