Reputation: 8786
I have an action bar that looks like so:
I am using the following to see which button is clicked:
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.view_all_trains:
Intent i = new Intent(ToStationActivity.this, MapActivity.class);
startActivityForResult(i, 0);
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
No matter what button you press, (the back or the pin), it goes back to the previous screen and I am not sure why. Any suggestions as to why this may happen?
Upvotes: 0
Views: 108
Reputation: 444
You need to finish the case at the end using break;
, else the control flow continues at the next case.
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.view_all_trains:
Intent i = new Intent(ToStationActivity.this, MapActivity.class);
startActivityForResult(i, 0);
break;
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
Upvotes: 1