Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity Navigation Logic

Tags:

android

I have 3 Activities...the first Activity have a button that start third Activity. The problem is: When I am in 3 - rd activity press "back" button its navigate me back to 1 - st Activity, but i need to 2 - nd one. My stack of Activities always should look like : 1. first Activity 2. second Activity 3. third Activity

How to do that ? Thanks...

like image 662
Jim Avatar asked Dec 09 '25 12:12

Jim


2 Answers

If the 2nd activity is not on the stack - which it sounds like it isnt, because you went from 1st -> 3rd - which means that in your 3rd activity you will have to implement onKeyDown and capture the BACK key, and then start a new Intent with the 2nd activity.

like image 131
Cody Caughlan Avatar answered Dec 11 '25 02:12

Cody Caughlan


You can intercept the back button from Activity 3:

@Override
public void onBackPressed() {
    // start Activity 2
    return;
}

See this article for more details.

Note: this only works with Android 2.0 or later.

like image 40
dbyrne Avatar answered Dec 11 '25 02:12

dbyrne



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!