Didac Perez Parera
Didac Perez Parera

Reputation: 3814

Finish all activities and restart application in Android

I would like to finish all the activities in an Android app and then restart it from the beginning. Is there an easy way to achieve this without finishing one by one until I come back to the first one?

Upvotes: 1

Views: 1628

Answers (1)

Mario
Mario

Reputation: 2739

Just clear the task when launching your intent.

Intent restartIntent = new Intent(this, MainActivity.class);
restartIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //Set this flag
startActivity(restartIntent);
finish();

Upvotes: 6

Related Questions