ViewHolder实现接口 androidx.lifecycle.LifecycleObserver;
image.png宿主中添加观察
ChatBotVideoVH chatBotVideoVH = new ChatBotVideoVH(new ChatBotVideoVH.Listener() {
@Override
public void onViewBookClick(String bookText) {
viewModel.sendBotBookTextMsg(bookText);
}
});
getLifecycle().addObserver(chatBotVideoVH);//重点
return chatBotVideoVH;
在ViderHolder注册事件
image.png
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroy() {
//关联宿主onDestory
if (mSimpleVideoView != null) {
mSimpleVideoView.release();
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void onPause() {
//关联宿主onPause
if (mSimpleVideoView != null) {
mSimpleVideoView.stop();
}
}
网友评论