Android menu shared between activities (unwanted)

I think I understood the Activity lifecycle on Android, but I still can't figure why the followin is happening.

  • Login activity - Login screen
  • Main activity - Main application interface

In Login activity, I connect to a service to validate the login. If the password is correct, I switch to Main activity using:

Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);

There is no Options menu in Login activity. I have an Options menu in Main activity that I inflate with:

    @Override
 public boolean onCreateOptionsMenu(Menu menu) {
     MenuInflater inflater = getMenuInflater();
     inflater.inflate(R.menu.option, menu);
     return true;
 }

So far so good. But I want the user to be able to log out and go back to login screen. So in Main activity I have an option in the menu that allows logging out:

   @Override
 public boolean onOptionsItemSelected(MenuItem item) {
     // Handle item selection
     switch (item.getItemId()) {
     case R.id.menuReset:
      getModel().deleteCredentials // stuff to logout from my service
      startActivity(new Intent(this, LoginActivity.class));
      finish();
      return true;
     }
 } 

If I press that menu button, the application displays Login activity again. But if I press the MENU key, the application displays the menu from Main activity even if it's not visible.

Furthermore, if I go back to home screen (pressing HOME) and come back to my activity after a while, the application displays the Login activity, but if I press the MENU key the Main application menu still shows.

How do I remove the menu from the Login activity?

Thanks

Answers


Oooooops, my bad. The inflate menu code was accidentally copied and pasted to Login Activity when I was coping another piece of code :)

Sorry about this Thanks anyway for the support!!


Need Your Help

sqldependency onchange firing in asp.net but asp.net Controls are not refreshing

c# asp.net sql-server-2008

sqldependency onchange firing in asp.net successfully and i am able to get Updated Data in Dataset but when it Binds the DataSet to Gridview it doesn't Refresh Itself.Furthermore No asp.net Page Life

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.