NavUtils.navigateUpTo() does not start any Activity

前端 未结 9 2147
陌清茗
陌清茗 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:23

    My solution to OPs problem:

    public void navigateUp() {
        final Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
            Log.v(logTag, "Recreate back stack");
            TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
        } else {
            NavUtils.navigateUpTo(this, upIntent);
        }
    }
    

    isTaskRoot() will return true if DeepLinkActivity is the root of a task (initial launch of application or application was previously terminated through task manager). This way I'm not loosing existing back stack if activity was launched through link when applications task was already in the foreground.

提交回复
热议问题