Search code examples
androidandroid-camerax

What happened to CameraX.unbindAll() method?


I'm trying to follow code samples I've found on the web (Gabriel Tanner, Ray Wenderlich, Official Introduction), but I usually get stymied on the very first line:

    CameraX.unbindAll()

Compiler complains that unbindAll() is an unresolved reference (Kotlin). The sample code from here is the only reference that does not use it. But all the other sample codes have it, including Google's own videos.

I can't even find any references to this method in Google's docs. What happened? Have changes in the past few months already made all these excited introductions obsolete?

I'm evaluating CameraX to see if it's worth our company's time to switch our code from Camera2 to CameraX. If things are changing this fast, what are the chances that significant code changes will happen in the future?


Solution

  • CameraX has gone through some changes since it was first introduced last year, this is normal since it was still in Alpha, the API surface was changing a bit throughout the alpha versions, but since it's gone into beta, its public API has become more stable.

    Going back to your question, binding and unbinding use cases in CameraX is no longer done through the CameraX class, but instead, it is now done using ProcessCameraProvider.bindToLifecycle() to bind one or multiple use cases to a lifecycle, ProcessCameraProvider.unbind() to unbind one or multiple use cases, and ProcessCameraProvider.unbindAll() to unbind all bound use cases.

    The tutorials you're using as reference are outdated, even the video from last year's google I/O is outdated, since the code snippets in it are referencing CameraX's first alpha version. However, the link of the codelab you mentioned is -almost- up to date, it's the official CameraX codelab that's maintained by Google. You can also take a look at the official documentation of CameraX, it's more up to date that the tutorials you referenced.