title: How to switch to front camera on CameraX?
body: <p>I've followed the steps <a href="https://codelabs.developers.google.com/codelabs/camerax-getting-started/#5" rel="noreferrer">here to get CameraX setup</a>, and now I am trying to get a front facing camera button working.</p>
  
  <p>Here is my set up code:</p>
  
  <pre><code>private lateinit var preview: Preview
  
  private fun startCamera() {
  
      // Create configuration object for the viewfinder use case
      val previewConfig = PreviewConfig.Builder().apply {
          setLensFacing(CameraX.LensFacing.BACK)
      }.build()
  
      // Build the viewfinder use case
      preview = Preview(previewConfig)
  
      // Every time the viewfinder is updated, recompute layout
      preview.setOnPreviewOutputUpdateListener {
  
          // To update the SurfaceTexture, we have to remove it and re-add it
          val parent = viewFinder.parent as ViewGroup
          parent.removeView(viewFinder)
          parent.addView(viewFinder, 0)
  
          viewFinder.surfaceTexture = it.surfaceTexture
          updateTransform()
      }
  
      // Bind use cases to lifecycle
      CameraX.bindToLifecycle(this, preview)
  }
  </code></pre>
  
  <p>When a user clicks the "switch" button I re-configure the preview to use the front camera, then reinitialize the Preview. </p>
  
  <pre><code>private fun initSwitchButton(view: View) {
      switchButton = view.findViewById(R.id.switch_button)
      switchButton.setOnClickListener {
          val previewConfig = PreviewConfig.Builder().apply { setLensFacing(CameraX.LensFacing.FRONT) }.build()
          preview = Preview(previewConfig)
      }
  }
  
  </code></pre>
  
  <p>However, this doesn't switch to the front camera. What am I missing?</p>