While passing Android DialogFragment arguments, onCreateDialog bundle agument is unexpectedly null

后端 未结 2 1962
太阳男子
太阳男子 2021-02-09 04:30

I am trying to display a basic dialog in Android using a DialogFragment using an argument for the dialog message as described in StackOverflow thread and DialogFragment document

相关标签:
2条回答
  • 2021-02-09 04:46

    you have to use getArguments to retrieve the Bundle you set with setArguments

    Instead of

    if(savedInstanceState != null) {
         dialogMessage = savedInstanceState.getString(DIALOG_MESSAGE);
    }
    

    you should have something like:

    Bundle bundle = getArguments();
    if (bundle != null) {
        dialogMessage = bundle.getString(DIALOG_MESSAGE);
    }
    
    0 讨论(0)
  • 2021-02-09 05:04

    I had the same problem, you have to use getArguments, as Blackbelt said.

    The savedInstanceState will be available when onSaveInstanceState (documentation) is called and some data is filled in outState, to be retrieved latter.

    0 讨论(0)
提交回复
热议问题