Reputation: 83
So here is the problem, I perform A → B and from B I do B → C , now when the back button is pressed in C I want to go back to A. so at start the flow is A → B → C but I want to clear B when I start C so when back pressed from C I go back to A. I know I can start A from C and CLEAR_TOP but I am looking for another alternative if there is one.
Thank You
Upvotes: 0
Views: 769
Reputation: 507
//FROM A TO B
Intent A = new Intent(A.this,B.class);
startActivity(A);
//FROM B TO C
Intent B = new Intent(B.this,C.class);
startActivity(B);
finish();
//FROM C TO A
onBackPressed(); you can go directly to A.
hope this may help u.
Upvotes: 2
Reputation: 93
Intent intent = new Intent(this, C.class);
startActivity(intent);
finish();
If you call finish() after start C Activity, in B Activity. You can remove B Activity from stack. So if you press back in C, you will see A Activity.
Upvotes: 1
Reputation: 5061
You just need to call finish()
Intent intent = new Intent(this, NextActivity.class);
startActivity(intent);
finish();
Upvotes: 3
Reputation: 11555
call finish();
after passing Intent on Activity you don't want to open on back press.
Upvotes: 2