Android - Starting a Timer using Handler

private final static int DELAY = 30000;
private final Handler handler = new Handler();
private Timer timer;

private void launchTimer() {
    TimerTask timerTask = new TimerTask() {

        @Override        public void run() {
            handler.post(new Runnable() {
                public void run() {
                    // TODO
                    // write the code to be executed after timer ends
                    timer.cancel();
                }
            });
        }
    };
    timer = new Timer();
    timer.schedule(timerTask, DELAY);
}

Comments

Popular posts from this blog

Android - Using KeyStore to encrypt and decrypt the data

Stack and Queue

Java Reflection API