title: ActivityResultLauncher not working with fragment?
body: <p>I'm writing an app using Kotlin.
  I'am using ActivityResultLauncher for get permission. I can use ActivityResultLauncher on Activity clearly but when I try to get permission on fragment with ActivityResultLauncher, the app goint to background without getting any error. I will put my code below. Please help me :)</p>
  <pre><code>private var selectedPictureUri: Uri? = null
  private lateinit var permissionLauncherForGallery: ActivityResultLauncher&lt;String&gt;
  private lateinit var activityResultLauncher: ActivityResultLauncher&lt;Intent&gt;
  
  
  override fun populateUI(savedInstanceState: Bundle?) {
          setClickListener()
          registerLauncher()
      }
  
  
  
  private fun selectMedia() {
      if (ContextCompat.checkSelfPermission(
              this,
              Manifest.permission.READ_EXTERNAL_STORAGE
          ) != PackageManager.PERMISSION_GRANTED
      ) {
          //request permission
          if (ActivityCompat.shouldShowRequestPermissionRationale(
                  this@WriteUsActivity,
                  Manifest.permission.READ_EXTERNAL_STORAGE
              )
          ) {
              Snackbar.make(
                  mBinding!!.root,
                  &quot;Permission needed for Gallery&quot;,
                  Snackbar.LENGTH_INDEFINITE
              ).setAction(&quot;Give Permission&quot;) {
                  permissionLauncherForGallery.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
              }.show()
          } else {
              permissionLauncherForGallery.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
          }
      } else {
          val intentToGallery =
              Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
          activityResultLauncher.launch(intentToGallery)
      }
  }
  
  
  
  private fun registerLauncher() {
          activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -&gt;
              if (result.resultCode == RESULT_OK) {
                  val intentFromResult = result.data
                  if (intentFromResult != null) {
                      selectedPictureUri = intentFromResult.data
  
                      if (selectedPictureUri != null) {  
                          mBinding?.ivPhoto?.visibility= View.VISIBLE
                          mBinding?.ivPhoto?.setImageURI(selectedPictureUri)
                      } else { 
                          val bundle = result.data!!.extras
                          val bitmap = bundle?.get(&quot;data&quot;)
                          mBinding?.ivPhoto?.setImageBitmap(bitmap as Bitmap)
                      }
                  }
              }
          }
          permissionLauncherForGallery =
              registerForActivityResult(ActivityResultContracts.RequestPermission()) { result -&gt;
                  if (result) {
                      //permission granted
                      if (ContextCompat.checkSelfPermission(
                              this,
                              Manifest.permission.READ_EXTERNAL_STORAGE
                          ) == PackageManager.PERMISSION_GRANTED
                      ) {
                          val intentToGallery =
                              Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
                          activityResultLauncher.launch(intentToGallery)
  
                      }
                  } else {
                      //permission denied
                      Toast.makeText(this, &quot;Permisson needed!&quot;, Toast.LENGTH_LONG).show()
                  }
              }
  
      }
  
  
  
  private fun setClickListener() {
      mBinding?.apply {
          btnPhoto.setOnClickListener {
              selectMedia()
          }
  
          btnPhoto2.setOnClickListener {
              this@WriteUsActivity.toast(&quot;Pick Second Photo&quot;)
          }
  
          btnSend.setOnClickListener {
              this@WriteUsActivity.toast(&quot;Save&quot;)
          }
      }
  }
  </code></pre>