Ignoring navigate() call: FragmentManager has already saved its state

前端 未结 5 2229
逝去的感伤
逝去的感伤 2021-02-08 01:19

I\'m using navigation in MainActivity, then I start SecondActivity (for result). After finish of SecondActivity I would like to continue w

5条回答
  •  情歌与酒
    2021-02-08 02:15

    I've solved this problem this way:

        @Override
    public void onActivityResult() { //inside my fragment that started activity for result
            model.navigateToResults = true; //set flag, that navigation should be performed
    }
    

    and then

        @Override
    public void onResume() { //inside fragment that started activity for result
        super.onResume();
    
        if(model.navigateToResults){
            model.navigateToResults = false;
            navController.navigate(R.id.action_startFragment_to_resultsFragment);
        }
    }
    

    not sure, if this is not a terrible hack, but it worked for me. FramgentManager state is restored at this point (onResume) and no problems with navigation occur.

提交回复
热议问题