What are the recommended cleanup steps when using ...
# compose
m
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
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
Simply use
LocalLifecycleOwner.current
with
bindToLifecycle()
. Navigation library provides a
LifecycleOwner
which is destroyed when you navigate away.
m
@Csaba Kozák Are you talking about the compose navigation component?
c
@Marwan Ehab yep, i do!
m
Okay thank you