title: Custom Lifecycle for CameraX
body: <p>I am trying to add a camera fragment using CameraX.but when i use this with viewPager(tablayout) i need camera to close when onPause() function called (as when i switch tab the camera should close ).but with default lifecycle of fragment it closes when fragment gets destroyed.</p>
  <p>Therefore i tried to make a custom lifecycle (code shown below). but it is not working camera doesn't even open</p>
  <pre><code>class CustomLifecycle : LifecycleOwner {
      private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(this)
  
      init {
          lifecycleRegistry.currentState = Lifecycle.State.CREATED
      }
  
      fun doOnResume() {
          lifecycleRegistry.currentState = Lifecycle.State.RESUMED
      }
  
      fun doOnDestroy() {
          lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
      }
      override fun getLifecycle(): Lifecycle {
          return lifecycleRegistry
      }
  }
  </code></pre>
  <p>binding cameraProvider to lifecycle</p>
  <pre><code>camera = cameraProvider.bindToLifecycle(
                  CustomLifecycle(), cameraSelector, preview, imageCapture, imageAnalyzer
              )
  </code></pre>
  <p>I don't have any idea how to make it work</p>
  <p>any suggestion will be appreciated</p>