Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Riley MacDonald
2,542 PointsAlert Dialog Popping up When it Should Not
I am currently doing the build a messaging app course and I am having trouble with this part of the code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch(itemId) {
case R.id.action_logout:
ParseUser.logOut();
navigateToLogin();
case R.id.action_edit_friends:
Intent intent = new Intent(this, EditFriendsActivity.class);
startActivity(intent);
case R.id.action_camera:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(R.array.camera_choices, mDialogListener);
AlertDialog dialog = builder.create();
dialog.show();
}
return super.onOptionsItemSelected(item);
}
According to the code above I would expect that when I click on "action_edit_friends" it should bring me directly to the EditFriendsActivity, however when I do this in the emulator the Alert Dialog I built below pops up for about half a second and then it goes into EditFriendsActivity. Could someone help me with this? I am sure I must be missing something very simple here!
Thanks, Riley
1 Answer
Ilya Sinotov
7,255 PointsYou should use break in case