How to restart an Activity?

2

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

    
asked by anonymous 15.08.2017 / 07:27

2 answers

1

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

  

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

    
15.08.2017 / 14:08
1

Completing Zulian's 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();
    
16.08.2017 / 01:22