Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear all activities

I have 4 activities: A, B, C and D. And one more: E.

Thre is no problem when y start a new activity between A, B, C and D. But in some points of these (for example, when a login is successful) we want to start activity E but clear all A, B, C and D activities (that is, clearing the back stack).

So, I want when yoy arrive to activity E, and press the back button, you will leave of the application.

I am trying do it adding flags in the startActivity: Intent.FLAG_ACTIVITY_CLEAR_TASK, Intent.FLAG_ACTIVITY_CLEAR_TOP and some more, but I can't achieve the behaviour.

Any idea?

Thanks!

like image 808
LopezAgrela Avatar asked Dec 05 '25 06:12

LopezAgrela


1 Answers

Intent intent = new Intent(this, EActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                this.startActivity(intent);
                this.finish();
like image 86
Artem Zelinskiy Avatar answered Dec 10 '25 06:12

Artem Zelinskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!