Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6552993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:31:39+00:00 2026-05-25T12:31:39+00:00

in an android app , I use menus for an activity <menu xmlns:android=http://schemas.android.com/apk/res/android> <item

  • 0

in an android app , I use menus for an activity

<menu
  xmlns:android="http://schemas.android.com/apk/res/android">
  <item 
  android:id="@+id/logout"
  android:title="Logout" />
  <item 
  android:id="@+id/compose"
  android:title="Compose"  />
  <item 
  android:id="@+id/refresh"
  android:title="Refresh" />
</menu>

and in activity :

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.inboxmenu, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.logout:
        SharedPreferences settings =getSharedPreferences("CASPreferences", MODE_PRIVATE);
        SharedPreferences.Editor prefEditor = settings.edit();
        prefEditor.putString("uid", "");
        prefEditor.putString("stdno", "");
        prefEditor.putString("firstname", "");
        prefEditor.putString("lastname", "");
        prefEditor.putString("lastname", "");
        prefEditor.commit();
        Intent myIntent = new Intent(this, LoginActivity.class);
        startActivity(myIntent);
        return true;
    case R.id.refresh:
        Log.e("menu" , "refresh");
        //Intent intent=new Intent(this,MainActivity.class);
        startActivity(getIntent());
        finish();
    case R.id.compose:
        Log.e("menu" , "compose");
        Intent intent1=new Intent(this,ComposeActivity.class);
        startActivity(intent1);




    default:
        return super.onOptionsItemSelected(item);
    }
}

but when I click on refresh button , it goes to compose activity ! like as you clicked on compose.

why does this happen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:31:40+00:00Added an answer on May 25, 2026 at 12:31 pm

    Rewrite your switch statement.

    switch (item.getItemId()) {
    case R.id.logout:
        ...
        return true;
    case R.id.refresh:
        ...
        finish();
        break; // <- Add this line
    case R.id.compose:
        ...
        break; // <- Add this line
    default:
        return super.onOptionsItemSelected(item);
    }
    

    Each case block must be enclosed by break.

    The break statements are necessary because without them, statements in switch blocks fall through: All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a break statement is encountered.

    break doesn’t required in first case block because flow interrupted by return statement.

    Reference: http://download.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following menu XML in my project: <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android>
I read http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html but have some issues. For pre-honeycomb I want a custom title,
I recently add another menu item to an android java app and was suprised
I'm working on an Android app in which I would like to use multi-touch.
How do I use gl.gluUnproject in my OpenGL ES 1.1 android app to determine
I found some examples in the web which use android.app.ActivityThread but I can't find
I'm writing an android app where I need to use AES. Is it better
I want to use a custom media controller in my Android app and therefore
I am trying to use a sendOrderedBroadcast in my Android app. I want to
I'm trying to use gluLookAt in an Android app to move the camera around,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.