Android - How to use Timers?
[Android] 2 ways to use timers:-
1. Using Handler
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
Log.i("Timer", "A second has passed");
handler.postDelayed(this, 1000);
}
};
handler.post(runnable);
2. Using CountDownTimer
new CountDownTimer(10000, 100) {
public void onTick(long ms) {
Log.i( "Seconds Left !!!", String.valueOf(ms/1000));
}
public void onFinish(){
Log.i( "Seconds Left !!!", "We are done !!");
}
}.start();
Ref Code:
App:
Comments