【问题标题】:Open new activity from actionbox menu item and close actually activity从操作框菜单项打开新活动并关闭实际活动
【发布时间】:2018-10-21 23:32:46
【问题描述】:

我怎样才能只打开一次活动?如果我在菜单中的同一项目上单击更多次,它会打开更多次。打开一个新的活动时,有没有办法关闭实际查看的活动?

@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);

}

【问题讨论】:

    标签: java android-activity menu


    【解决方案1】:

    好的,我找到了清除顶部的 soulion 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);
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多