title: IllegalStateException Can not perform this action after onSaveInstanceState show DialogFragment
body: <p>This is the very first time I ever encounter this problem.</p>
  <p>I already took a long look to the several answers on SO, especially <a href="https://stackoverflow.com/questions/7469082/getting-exception-illegalstateexception-can-not-perform-this-action-after-onsa">this one</a> and <a href="https://stackoverflow.com/questions/7575921/illegalstateexception-can-not-perform-this-action-after-onsaveinstancestate-wit">this one</a> but it didn't solve my problem and most of the answers can't be used as a safe and robust way to solve my cases.</p>
  <p>I already tried to:</p>
  <ul>
  <li>override <code>onSaveInstanceState</code> and do not call super</li>
  </ul>
  <p>but commitAllowingStateLoss can't be used on the first case.</p>
  <p>I'm looking for an explanation on how to AVOID to get this exception thrown and how to achieve the action which has thrown the exception (in the first case, show the dialogFragment). I already got how this exception is thrown, however, I don't know what it is thrown in my situation.
  It appears twice in my app:</p>
  <p>The first one occurs in a very simple activity, I have a simple animation and at the end of this animation I show a DialogFragment (SplashActivity):</p>
  <pre><code>override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      val potentialLanguage = storage.getString(Constants.LANGUAGE)
      val lang = if (potentialLanguage.isNotEmpty()) {
          potentialLanguage
      } else {
          Locale.getDefault().language
      }
      val language = Language.getFromName(lang)!!
      val dm = res.displayMetrics
      val conf = res.configuration
      conf.setLocale(Locale(language))
      saveLanguage(context, lang)
      // Use conf.locale = new Locale(...) if targeting lower versions
      res.updateConfiguration(conf, dm)
      initWarningDialog()
      RevelyGradient
          .radial()
          .colors(
              intArrayOf(
                  getColor(R.color.backgroundOnBoardingStart),
                  getColor(R.color.backgroundOnBoardingEnd)
              )
          )
          .onBackgroundOf(root)
      ivCap.animate()
          .alpha(1f)
          .setListener(object : Animator.AnimatorListener{
              override fun onAnimationEnd(p0: Animator?) {
                  try {
                      commonDialog.show(supportFragmentManager, &quot;CommonDialogSplash&quot;) //crash here commonDialog is a DialogFragment
                  }
                  catch (e: IllegalStateException){
                      try {
                          startActivity(Intent(this@SplashActivity, MainActivity::class.java))
                          finish()
                      }
                      catch (e: IllegalStateException){
  
                      }
                  }
              }
  
              override fun onAnimationCancel(p0: Animator?) {
  
              }
  
              override fun onAnimationRepeat(p0: Animator?) {
  
              }
  
              override fun onAnimationStart(p0: Animator?) {
  
              }
          }).duration = 1000
  }
  
  private fun initWarningDialog(){
      commonDialog.isCancelable = false
      commonDialog.setTitle(getString(R.string.warning))
      commonDialog.setFirstTextButton(getString(R.string.ok))
      commonDialog.setDescription(getString(R.string.warning_message))
      commonDialog.setFirstButtonListener(object : CommonDialog.CommonDialogClickListener {
          override fun onClick() {
              commonDialog.dismiss()
              startActivity(Intent(this@SplashActivity, MainActivity::class.java))
              finish()
          }
      })
  }
  </code></pre>
  <p>The second one is when I try to add a fragment after a firebase firestore request (TotoFragment):</p>
  <pre><code>fun pullChallenges(){
          val db = Firebase.firestore
          val docRef = db.collection(&quot;challenges&quot;).document(language.name.toLowerCase(Locale.ROOT))
          docRef
              .get()
              .addOnSuccessListener { result -&gt;
                  result.data?.let {data -&gt;
                      data.values.map {values-&gt;
                          val alOfHm = values as ArrayList&lt;HashMap&lt;String, String&gt;&gt;
                          for (item in alOfHm){
                              val challenge = Challenge()
                              Challenge.ChallengeCategory.getValueOf(item[&quot;category&quot;]!!)?.let {
                                  challenge.challengeCategory = it
                              }
                              Game.GameMode.getValueOf(item[&quot;mode&quot;]!!)?.let {
                                  challenge.mode = it
                              }
                              challenge.challenge = item[&quot;content&quot;]!!
                              challenges.add(challenge)
                          }
                      }
                  }
                  ChallengesManager.challenges = challenges
                  listener.onChallengesReady(true)
              }
              .addOnFailureListener { exception -&gt;
                  listener.onChallengesReady(false)
                  Timber.e(&quot;Error getting challenges $exception&quot;)
              }
      }
  
   override fun onChallengesReady(success: Boolean) {
          renderLoading()
          if (success) {
              try {
                  goToChooseMode()
              }
              catch (e: IllegalStateException){
  
              }
          }
          else {
              Toast.makeText(requireContext(), getString(R.string.error_get_caps), Toast.LENGTH_SHORT).show()
          }
      }
  
      private fun goToChooseMode(){
              val bundle = Bundle()
              bundle.putStringArrayList(Constants.PLAYERS, ArrayList(viewModel.players))
              activity.supportFragmentManager
                  .beginTransaction()
                  .addToBackStack(ChooseModeFragment::class.java.name)
                  .setReorderingAllowed(true)
                  .add(R.id.fragmentContainer, ChooseModeFragment::class.java, bundle, ChooseModeFragment::class.java.name)
                  .commit()
          }
  </code></pre>
  <p>Any help of understand this problem (for the thought, or some explanations on the problem, or quick fix...)</p>