Is there a way to get a callback when an AndroidVi...
# compose
s
Is there a way to get a callback when an AndroidView is being detached before the view is detached from the window? I’m trying to get a bitmap of the last frame played in ExoPlayer before the view is removed.
a
should be able to use a standard attach state change listener, e.g.
Copy code
AndroidView(
    factory = { context ->
        View(context).apply {
            addOnAttachStateChangeListener(
                object : View.OnAttachStateChangeListener {
                    override fun onViewAttachedToWindow(v: View?) {}

                    override fun onViewDetachedFromWindow(v: View?) {
                        TODO("Not yet implemented")
                    }
                }
            )
        }
    }
)
s
That is called after
releaseSurfaceTexture
is called in the
TextureView
So it’s too late to get the bitmap
a
ah, I'm not familiar enough with exoplayer's expected lifecycle for that then. You should be able to use the same basic idea with a more appropriate exoplayer callback