0

从选项菜单启动活动时遇到问题。按下注销时,我需要进入注销活动。但什么也没发生。这是我的代码:

public class MenuActivity extends Activity {

public void onCreate(Bundle menuinstance) {
    super.onCreate(menuinstance);
    setContentView(R.layout.mainmenu);

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

@Override 

    public boolean onOptionsItemSelected(MenuItem item){

        switch (item.getItemId()) {
        case R.id.Logout:
            startActivity(new Intent("com.project.myAndroid.Logout"));
            break;}
        return true;
    }
}
4

1 回答 1

0

请写下:

switch (item.getItemId()) {
    case R.id.Logout:
startActivity(new Intent(MenuActivity.this, Logout.class));
break;}
return true;

代替 :

switch (item.getItemId()) {
    case R.id.Logout:
startActivity(new Intent("com.project.myAndroid.Logout"));
break;}
return true;
于 2014-03-13T15:34:30.807 回答