We have the first activation, with it we go to the 2nd, on the second there is a Back button and there is a hardware Back button. If I switch to the 2nd activation, and then come back with one of the 2 options, everything is fine - I again find myself on the first activation, but if I click on Back , then I will be transferred again to this activation, i.e. 1 more copy is stored on the stack. The question is how to properly organize these transitions?

public void cancelAction(View v) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); } 
  • And what is the return button code? do not accidentally create a new activity through intent? - KoVadim

1 answer 1

You have a bad code to go back. You simply create a new activity that you put on the stack. That is, if you open and close activations in this way, there will be a whole bunch of MainActivity in the stack. It is for this reason that the "Back" button does not work. What to do? rather than creating a new activation, just call finish ();

  • Thanks, Thu did not think right away - Gorets '11