What are the recommended cleanup steps when using CameraX with jetpack compose if the camera screen is not the only screen in my application?
So when I navigate from some screen to a screen using the camera where should the cameraProvider/PreviewView/etc... be initialized and how should I clean everything up when leaving the camera screen
k
Kilian
09/19/2023, 3:00 PM
i do it in a viewmodel and then use some viewmodel.dispose/clear functionality.
This could either be called by the component that navigations or you can make an Disposable Effect that calls this in onCidpose
c
Csaba Kozák
09/20/2023, 8:22 AM
Simply use
LocalLifecycleOwner.current
with
bindToLifecycle()
. Navigation library provides a
LifecycleOwner
which is destroyed when you navigate away.
m
Marwan Ehab
09/21/2023, 6:40 AM
@Csaba Kozák Are you talking about the compose navigation component?