How to click option menu open new activity?
I am can just click option menu and show message but can't click optin menu and open new activity
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manoj BhoirRank #599 · 4K reputationPosted Jun 6, 2015, 8:19 PM EDT
You have to override
onOptionsItemSelectedmethod in your Activity, which is called when user clicks on the item in Options menu. In the method you can check what item has been clicked.public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_item1:
Intent intent = new Intent(this, ActivityForItemOne.class);
this.startActivity(intent);
break;
case R.id.menu_item2:
// another startActivity, this is for item with id "menu_item2"
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
Neeraj KumarRank #355 · 7K reputationPosted Jul 3, 2015, 10:18 AM EDT
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.d(TAG, "onOptionsItemSelected()"); switch (item.getItemId()) { case android.R.id.home: finish(); return true; case R.id.menu_item_comment: return true; default: return super.onOptionsItemSelected(item); } }