title: unsaved warning on back pressed in fragment
body: <p>I want to show dialog when user press back or quit from fragment if there are some data unsaved. I am trying to override onbackpressed but unfortunately I got error <code>lateinit property barcodeList has not been initialized</code>. how to solve it?</p>
  
  <p>here is my script on activity:</p>
  
  <pre><code>override fun onBackPressed() {
      val theFragment = supportFragmentManager.fragments
      for(i in 0 until theFragment.size)
      {
          if(theFragment[i].tag == "stocker_fragment")
          {
              StockerFragment().onBackPressed()
          }
      }
  }
  </code></pre>
  
  <p>and this is in fragment:</p>
  
  <pre><code>fun onBackPressed() {
      var check = false
       // this barcodeList variable error.
      for(i in 0 until barcodeList.size)
      {
          if(barcodeList[i].barcode.trim()=="")
          {
              check = true
              break
          }
      }
  
      if (check)
      {
          AlertHelper(context).onBackPressedAlert()
      }
  }
  </code></pre>
  
  <p>FYI: I have initialized barcodeList on onCreateView and everything is fine. only error in onBackPressed.</p>
  
  <p>And my last question is, how do i know if user quit from fragment without pressing back button?</p>