How to give Restart in an Activity?

Asked

Viewed 759 times

2

I want to re-start my activity without the help of buttons, I want it to restart automatically within a while. How do I do this?

2 answers

1


To restart a Activity you can use the method recreation(), available from API 11.

Make this Activity be recreated with a new instance. This results in the same flow when Activity is created due to a configuration change -- the current instance will run its life cycle until onDestroy(), and a new instance will be created later.

1

Completing the Zulian response, you can put this code in the creation of Activity:

new CountDownTimer(RESTART_TIME, 1000) {
    public void onTick(long millisUntilFinished) {}

    public void onFinish() {
        recreate();
    }
}.start();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.