Timer와 TimerTask를 이용한 반복 작업 구현.
아래 예제는 15초 동안 5초마다 한번 씩 작업하는 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Timer timer = new Timer(); | |
TimerTask TT = new TimerTask() { | |
@Override public void run() { | |
// Do something... | |
} | |
}; | |
timer.schedule(TT, 5000, 15000); |
CountDownTimer를 이용한 반복 작업 구현.
아래 예제는 10초 동안 0.5초마다 한번 씩 작업하는 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CountDownTimer progress = new CountDownTimer(10000, 500) { | |
public void onTick(long millisUntilFinished) { | |
// Do something... | |
} | |
public void onFinish() { | |
} | |
}; | |
progress.start(); |
아래 예제는 1초 후에 한번 작업하는 예제
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Handler().postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
// Do something | |
} | |
}, 1000); |
댓글 없음:
댓글 쓰기