经测试,当在onStop方法里显示DialogFragment是,会出现IllegalStateException异常:Can not perform this action after onSaveInstanceState...
但是在onPause方法里启动DialogFragment不会出现问题
通过上面两点可以再当前的onStop和onResume方法里记录变量,来表示当前activity的状态是否适合启动DialogFragment。
注意:
protected void onSaveInstanceState (Bundle outState)
If called, this method will occur before
onStop()
. There are no guarantees about whether it will occur before or after onPause()
.
所以,在onPause()和onSaveInstanceState()方法里同时设置变量状态,则不会出现此问题。