0

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

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
Astronautilus
  • 83
  • 1
  • 9

5 Answers5

3

You just need to call finish()

Intent intent = new Intent(this, NextActivity.class);
startActivity(intent);
finish();
Nithinlal
  • 4,845
  • 1
  • 29
  • 40
2

call finish(); after passing Intent on Activity you don't want to open on back press.

Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
2

you can call finish(); after you start intent on B .

Ahmed Eltaher
  • 161
  • 1
  • 8
2
    //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.

Varma460
  • 497
  • 1
  • 4
  • 13
1
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.

ekilic
  • 83
  • 8