title: How to save the state of dialog box after it has been dismissed
body: <p>I have Dialog box to enter pin. if user enters the invalid pin it starts the timer.
  When i dismiss the dialog box on back button and then again opens the dialog box on item click it resets it states and timer is gone.Its a pin dialog box . when user enters the wrong pin a timer starts under pin layout such that he cannot enter pin for that particular time for eg: 30 seconds. While 30 seconds count down is running and i close the dialog box and immediately open it again timer is gone and it has new state.</p>
  <p><em><strong>How to save the state of dialog box after dismiss such that timer runs in background and when i open it again it shows the state where timer is running? need help regarding this</strong></em></p>
  <p><strong>onItemClick it opens dialog box():</strong></p>
  <pre><code>lockCardView.setOnClickListener {
               showEnterPinDialog(Input.fromNullable(ItemList))
                              }
  
  fun showEnterPinDialog(ItemList: Input&lt;ArrayList&lt;String&gt;&gt;) {
          var dialog = EnterPinDialog(activity.requireActivity(),Repository, ItemList)
          dialog.show()
          dialog.setCanceledOnTouchOutside(false)
      }
  </code></pre>
  <p><strong>DialogBox code:</strong></p>
  <pre><code>class EnterPinDialog(
      context: Context,
      var Repository: ItemRepository,
      var ItemList: Input&lt;ArrayList&lt;String&gt;&gt;
  ): Dialog(context) {
  
      lateinit var dataBind : EnterPinDialogBinding
  
      var itemPinList: ArrayList&lt;String&gt; = ArrayList()
      var confirm_pin :String? = null
      var sum = 0
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          dataBind = DataBindingUtil.inflate(layoutInflater, R.layout.enter_pin_dialog, null, false)
          setContentView(dataBind.root)
          dataBind.materialTextView53.visibility = View.GONE
          dataBind.pinView.transformationMethod = AsteriskPasswordTransformationMethod()
          dataBind.pinView.addTextChangedListener(object : TextWatcher{
              override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
  //                TODO(&quot;Not yet implemented&quot;)
              }
  
              override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
  //                TODO(&quot;Not yet implemented&quot;)
                  confirm_pin = s.toString()
                  val epin = md5(confirm_pin!!)
                  for (ls in itemPinList.indices){
                      if (s!!.length&gt;5) {
                          if (epin.equals(itemPinList.get(ls).toString())) {
                              setItemLockAPi(ItemList, false)
  
                           
                                      dismiss()
                                  }
                              }, 1500)
                          }
                          else
                          {
                              sum++
                              dataBind.pinView.setLineColor(
                                  ContextCompat.getColor(
                                      dataBind.root.context,
                                      R.color.red
                                  )
                              )
                              dataBind.materialTextView53.visibility = View.VISIBLE
                              dataBind.pinView.text?.clear()
                              dataBind.attemptsLeft.visibility = View.VISIBLE
                              dataBind.attemptsLeft.text = &quot;${3 - sum} attempts left&quot;
                              if(sum == 3){
                                  dataBind.attemptsLeft.visibility = View.GONE
                                  dataBind.materialTextView53.visibility = View.GONE
                                  dataBind.failedAttempts.visibility = View.VISIBLE
                                  dataBind.pinView.clearFocus()
                                  dataBind.pinView.isEnabled = false
                                  dataBind.timerThirty.visibility = View.VISIBLE
                                  object : CountDownTimer(30000, 1000) {
  
                                      // Callback function, fired on regular interval
                                      override fun onTick(millisUntilFinished: Long) {
                                          dataBind.timerThirty.text = &quot;${millisUntilFinished / 1000} Seconds&quot;
                                      }
  
                                      // Callback function, fired
                                      // when the time is up
                                      override fun onFinish() {
  //                                    textView.setText(&quot;done!&quot;)
                                          dataBind.pinView.isEnabled = true
                                          dataBind.failedAttempts.visibility = View.GONE
                                          dataBind.pinView.setLineColor(
                                              ContextCompat.getColor(
                                                  dataBind.root.context,
                                                  R.color.white
                                              )
                                          )
                                          dataBind.timerThirty.visibility = View.GONE
                                          sum = 0
                                      }
                                  }.start()
                              }
                          }
                      }
                  }
              }
  
              override fun afterTextChanged(s: Editable?) {
  //                TODO(&quot;Not yet implemented&quot;)
              }
  
          })
  
          dataBind.backPin.setOnClickListener {
              dismiss()
          }
  
      }
  </code></pre>