```Why enter twice?``` ``````
# android
e
Copy code
Why enter twice?
``````
g
Becauses of recomposition
you really shouldn’t do this
composable can be called multiple times, you do not handle lifecycle callback corretly, yu adding it on every recompoise
e
Copy code
is there another optimal way to know the life cycle? I need to know when it goes to destroy to free up resources
g
What are you trying to achieve?
p
your scope lifecycle should be driven by navigation and not by composition
I would add a OnDestinationChangedListener to the navController and control the lifecycle from there
e
Copy code
I need to delete the ExoPlayer instance
Copy code
in a fragment it would be canceling the onDestroy method, in this new approach I don't know very well where to release it, so I was looking for a way to know the life cycle
g
So you want to release player onDestroy or when composable is removed from screen? It’s not the same
If you just want have fragment lifecycle, just create player onCreate and release onDestroy of fragment
if you want to scope it to composable, you probably need DisposableEffect: https://developer.android.com/jetpack/compose/side-effects#disposableeffect
e
Copy code
I found this way of doing it and I would like to know your opinion, as I understand it is only invoked once factory of AndroidView, it is there that when the screen is destroyed I call destroy () that is executed in the context of the activity and I can free the resources and destroy the ExoPlayer instance
g
It still looks a bit strange for me, and just a pure hack