我让它工作了!这是解决方案:
nowActivity.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.menuItem1:
Toast.makeText(this, "Du är redan på startsidan", Toast.LENGTH_SHORT).show();
return false;
case R.id.menuItem2:
Intent b = new Intent(nowActivity.this, About.class);
b.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(b);
return true;
case R.id.menuItem3:
android.os.Process.killProcess(android.os.Process.myPid());
return true;
default:
return super.onOptionsItemSelected(item);
}
}
关于.java
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuItem1:
Intent a = new Intent(About.this, nowActivity.class);
a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(a);
return true;
case R.id.menuItem2:
Toast.makeText(this, "Du är redan på \"Om\"-sidan", Toast.LENGTH_SHORT).show();
return false;
case R.id.menuItem3:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
System.exit(0);
return true;
default:
return super.onOptionsItemSelected(item);
}
}