Up navigation broken on JellyBean?

后端 未结 2 1058
北荒
北荒 2020-11-28 03:49

Source code is available here: https://github.com/novemberox/NavigationTest It\'s modified version of this sample: http://developer.android.com/training/implementing-navigat

2条回答
  •  醉话见心
    2020-11-28 04:33

    After reading @cyfur01's answer, I came up with very simple solution that fixes the behavior.

    Override this method in your Activity (or ideally in some BaseActivity to have it fixed for all subclasses) and it should work as expected:

    @Override
    public boolean navigateUpTo(Intent upIntent) {
        boolean result = super.navigateUpTo(upIntent);
        if (!result) {
            TaskStackBuilder.create(this)
                .addNextIntentWithParentStack(upIntent)
                .startActivities();
        }
        return result;
    }
    

    It leaves all work to Android implementation and then just checks return value of navigateUpTo(upIntent) which is false when an instance of the indicated activity could not be found and this activity was simply finished normally. Which is exactly the case when we want to create and start the parent Activities manually. Also note we don't have to call finish() here as it was called by the super method.

提交回复
热议问题