SoldierCorp
SoldierCorp

Reputation: 7700

Android: How to show menu only in specific activities?

I've many activities in my project and one activity for Login but I want that only show menu in all activities except in activity login, because in that menu will be an icon of end session and when press, return to the login activity. And not how, could you help me?

Upvotes: 0

Views: 742

Answers (2)

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

Better to an base activity which contains your code for menus and then you can extend it your activities instead of activity.

And for login you can extend activity. so all the activities which extend baseactivity will be reflected with menu with out need to write menus code in every activity. and for the will be no menu as it does not extend base activity.

Updated:::

public class BaseActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }
     /* Creates the menu items */
    public boolean onCreateOptionsMenu(Menu menu) {
          MenuInflater inflater = getMenuInflater();
          inflater.inflate(R.menu.options_menu, menu);
          return true;
    }

        /* Handles item selections */
        public boolean onOptionsItemSelected(MenuItem item) {
            switch(item.getItemId())
            {       
                case R.id.menu1:
                                           //your stuff
                break;
                case R.id.menu2:
                                           //your stuff
                break;
            }
        return true;
        }

}

Upvotes: 0

Jonathan García
Jonathan García

Reputation: 839

I would recommend that the layout for login does not have the menu and the layout of other activities if the menu has

Upvotes: 2

Related Questions