[英]Open new activity from actionbox menu item and close actually activity
我怎么只能打开一个活动? 如果我在菜单中的同一项目上单击更多次,则会打开更多次。 打开新活动时,是否可以关闭实际查看的活动?
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//menu item clickd
if (id == R.id.share) {
startActivity(new Intent(MainActivity.this, HowToUse.class));
return true;
}
if (id == R.id.terms) {
Intent intent = new Intent(this,InfoAbout.class);
this.startActivity(intent);
return true;
}
if (id == R.id.howuse) {
Intent intent = new Intent(this,HowToUse.class);
this.startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
好吧,我找到了灵魂乐团add.Flags清除顶部
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//menu item clickd
if (id == R.id.share) {
startActivity(new Intent(MainActivity.this, HowToUse.class));
return true;
}
if (id == R.id.terms) {
Intent intent = new Intent(this,InfoAbout.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
if (id == R.id.howuse) {
Intent intent = new Intent(this,HowToUse.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.