[英]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.