user1529522
user1529522

Reputation: 13

Have to touch back button twice to go to previous activity

I am quite new to Android so please be patient.

When you start a new activity, by default, the Back button on the device should take you back to the previous activity.
In my case I have to press the back button twice before it goes back to the previous activity.

Please advise

Upvotes: 0

Views: 965

Answers (1)

Alexis C.
Alexis C.

Reputation: 93842

private int count = 0;

@Override
public void onBackPressed() {
    count++;
    if (count == 2) {
        //Do your stuff here
        count = 0;
    }    
}

Upvotes: 3

Related Questions