0

I have a menu on my application. The problem is that, when I click on an item, the previous one stays behind. So when I click on the previous button of my phone, the previous activity appears. I don't know what is going wrong with my code.

So this is my code for the menu :

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.action_user:
            Intent intent1 = new Intent(TeamActivity.this, UserActivity.class);
            startActivity(intent1);
            return true;
        case R.id.action_team:
            return true;
        case R.id.action_score:
            Intent intent2 = new Intent(TeamActivity.this, ScoreActivity.class);
            startActivity(intent2);
            return true;
        case R.id.action_settings:
            Intent intent3 = new Intent(TeamActivity.this, SettingsActivity.class);
            startActivity(intent3);
            return true;
        case R.id.action_about:
            Intent intent4 = new Intent(TeamActivity.this, AboutActivity.class);
            startActivity(intent4);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

I hope you understand, and sorry for my bad english

  • Android OS internally maintains a stack of activities. What is your requirement? You do not want your previous activity to appear on back press event? – Green goblin Apr 21 '14 at 19:40
  • IMHO, that's how it should work. If you don't need current activity in the backstack, do what CarbonAssassin said: call finish, that will remove current activity from backstack, but you can't go back to that activity anymore. – IuriiO Apr 21 '14 at 20:54
  • Thanks for your answers. So that is totally normal the animation when I click on an Item ? I thought it was anormal, as the stack can be very important... –  Apr 21 '14 at 22:34

1 Answers1

0

Simply add this.finish(); after each startActivity() before returning true!

CarbonAssassin
  • 855
  • 12
  • 24