user10322505
user10322505

Reputation: 5

Android phone built-in back button

I have an activity with two fragments, each fragment has a back button to the previous activity/fragment. Both the back buttons on the fragments work properly. However when i run the app on my android phone and i use the built-in back button to navigate to the previous activity, it displays a blank activity and then when i press the built-in back button again only then does it navigate to the previous activity. The problem is clearly the back burton than built in.Is there a way to solve this???

Upvotes: 0

Views: 525

Answers (1)

N. Matic
N. Matic

Reputation: 313

There is a method in the Activity called onBackPressed() which is called when the device back button is pressed. If you want to control what happens on back press just override it. To remove default onBackPressed action you need to remove the call to super.onBackPressed() and then you control what happens when back button is pressed.

@Override
    public void onBackPressed() {
        //super.onBackPressed();
        // do something here
        // or perhaps nothing at all
    }

Upvotes: 1

Related Questions