我在显示警告对话框之前保存了一个键值对。但是,对话框的 onCreateDialog()
是使用空包调用的。我需要做些什么才能将 bundle 传递给对话框吗?
MyDialogFragment testFrag= new MyDialogFragment();
Bundle args = new Bundle();
args.putString("car-type", "Audi");
testFrag.setArguments(args);
testFrag.show(getFragmentManager(), "info");
最佳答案
您可以通过 DialogFragment.getArguments()
检索参数。
savedInstanceState
仅在发生配置更改时使用。它在 onSaveInstanceState(Bundle outState)
中被填充,随后在 onCreate()
和 onCreateView()< 中传递给新的
。第一次创建 Fragment 或 Activity 时,它是 DialogFragment
/null
。
关于android - 保存的实例包在 DialogFragment 的 onCreateView 中为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28286979/