Reputation: 4307
I am developing a small application at the moment it consists on 3 Activities.
Now when I start my application it starts fine and I can navigate from activity1 to activity 3 properly and without any problem.
Activity1-->Activity2--->Activity3
The problem comes that when I press the back button of my mobile device to go back to activity2, the application simply closes.
Can somebody please suggest how to figure it out what is happening.
that is how i am going to Activity2 from Activity2
Intent activity3 = new Intent(Activity2.this,Activity3.class);
Activity2.this.startActivity(activity3);
Activity2.this.finish();
Note:I am not using emulator I am using mobile and doing all the debugging directly on the mobile. Thanks
Upvotes: 0
Views: 111
Reputation: 2097
Because you call finish() method.
Due to this from activity stack your last activity is removed so that's way your current activity is finished on backPressed().
To overcome this You must remove
Activity2.this.finish(); from your code.
Upvotes: 2
Reputation: 3855
This is because you are calling the finish() function which removes the activity from the stack. Remove the line Activity2.this.finish();
and you should be going back the way you wanted.
Upvotes: 3