1

sometimes, i will get a

java.lang.IllegalStateException Can not perform this action after onSaveInstanceState

when i try to show a DialogFragment.

so now the question is how i can write a if statement to judge current state before i involve the show method like this?

if(!isAfterOnSaveInstanceState()) 
    dialog.show(getSupportFragment(),"MY DIALOG");

because i notice that the DialogFragment own the method dismissAllowingStateLoss() but lack of a method to allow state loss when show, maybe the design of the DialogFragent want developers to judge before call show method.

Thanks in advance.

SDJSK
  • 1,292
  • 17
  • 24

1 Answers1

0

onSaveInstanceState(): If called, this method will occur before onStop(). There are no guarantees about whether it will occur before or after onPause(). you can check isFinishing() before show your DialogFragment

if(!isFinishing()) {
// your code goes here... 
}

more detail:link-1,link-2,link-3

Community
  • 1
  • 1
Tanim reja
  • 2,120
  • 1
  • 16
  • 23