title: Zxing QR code scanner code is not working in a fragment
body: <p>I am trying to develop QR code scanner App using Zxing library in Kotlin. I am able to open the camera and scan the QR code but not getting response.</p>
  
  <p>I also tried <a href="https://tutorialwing.com/implement-android-qr-code-scanner-using-zxing-library-in-kotlin/" rel="nofollow noreferrer">this tutorial</a> for implementation but did not get helped.</p>
  
  <pre><code>class HomeFragment : Fragment() {
  
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
          return inflater.inflate(R.layout.fragment_home, container, false)
      }
      override fun onActivityCreated(savedInstanceState: Bundle?) {
          super.onActivityCreated(savedInstanceState)
          val mScanner = IntentIntegrator(activity)
          mScanner.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
          mScanner.setBeepEnabled(true)
          mScanner.initiateScan()
  
      }
      override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
          val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
          if (result != null) {
              if (result.contents == null) {
                  Toast.makeText(activity, "Cancelled", Toast.LENGTH_LONG).show()
              } else {
                  Toast.makeText(activity, "Scanned: " + result.contents, Toast.LENGTH_LONG).show()
              }
          } else {
              super.onActivityResult(requestCode, resultCode, data)
          }
      }
  }
  </code></pre>
  
  <p>I want to get response in a toast but when I tried to use debugger I am unable to go to onActivityResult() and the camera closes quickly.</p>