user243351
user243351

Reputation: 1

overriding onBackPressed() is still closing the activity

I am overriding onbackPressed() but it is still finishing the activity. If the score view is up then on back pressed goes to another activity and that works. However if the scoreview is not up and the game is going I want a pause menu to become visible so they can choose whether to resume or go home, but what happens is it comes up for a split second and the activity finishes() and I have no idea why. I have print statements at all my finishes and none appear. Does the back button always finish the current activity and the reason why the other option is working is because I am starting another activity. if so is there an easy way to override that. Any other reason why this might happen. Is there a way I can see where the activity was finished in the log cat.

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    //stop computer tile flips and person tile flips
    if(gamescreenup){
    Log.d("back button baseactivity", "goinh home");
    Intent home = new Intent (this, HomeScreen.class);
    startActivity(home);
    overridePendingTransition(R.anim.anim3, R.anim.anim4);
    finish();
    }else{
        Log.d("back button baseactivity", "displaying pause");
        gamepausebool = true;
        going = false;
        Log.d("bools changed", "changing vis next");
        linlay.setVisibility(View.VISIBLE);
        Log.d("vis changed", "made it here");
    }
}

Upvotes: 0

Views: 331

Answers (2)

Emanuel
Emanuel

Reputation: 8106

Remove super since it's the same as finish().

Upvotes: 1

Sebastien Bianchi
Sebastien Bianchi

Reputation: 722

Remove super.onBackPressed(); . It's what is causing your issue.

Upvotes: 3

Related Questions