NavUtils.navigateUpTo() does not start any Activity

前端 未结 9 2140
陌清茗
陌清茗 2021-01-30 06:48

I have two activities

  • MainActivity
  • DeepLinkActivity

I set up everything to use the NavUtils for navi

9条回答
  •  爱一瞬间的悲伤
    2021-01-30 07:32

    Try this :

    @Override
    public boolean onOptionsItemSelected(final MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                Intent upIntent = NavUtils.getParentActivityIntent(this);
                if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                    // create new task
                    TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent)
                            .startActivities();
                } else {
                    // Stay in same task
                    NavUtils.navigateUpTo(this, upIntent);
                }
                break;
            default:
                return super.onOptionsItemSelected(item);
        }
        return true;
    }
    

提交回复
热议问题