Audio 如何销毁RecyclerView中的所有Web视图?
我在适配器中传递了5个音频,在onbind中,我在webview中加载该url,当我按下后退按钮音频未停止时,我销毁webview,但它在最后一个webview项目位置工作 我在适配器中传递了5个声音云嵌入url 用于销毁WebviewAudio 如何销毁RecyclerView中的所有Web视图?,audio,webview,android-webview,android-recyclerview,Audio,Webview,Android Webview,Android Recyclerview,我在适配器中传递了5个音频,在onbind中,我在webview中加载该url,当我按下后退按钮音频未停止时,我销毁webview,但它在最后一个webview项目位置工作 我在适配器中传递了5个声音云嵌入url 用于销毁Webview public void destroyWebView() { if(videoWebView != null) { videoWebView.loadUrl(""); videoWebView.lo
public void destroyWebView() {
if(videoWebView != null) {
videoWebView.loadUrl("");
videoWebView.loadData("", "text/html" , "utf-8" );
videoWebView.clearHistory();
// NOTE: clears RAM cache, if you pass true, it will also clear the disk cache.
// Probably not a great idea to pass true if you have other WebViews still alive.
videoWebView.clearCache(true);
// Loading a blank page is optional, but will ensure that the WebView isn't doing anything when you destroy it.
videoWebView.loadUrl("about:blank");
videoWebView.onPause();
videoWebView.removeAllViews();
videoWebView.destroy();
// Null out the reference so that you don't end up re-using it.
videoWebView = null;
}
}
当用户按下后退按钮时,我调用此函数
@Override
public void onBackPressed() {
meditationFavSCAdapter.destroyWebView();
super.onBackPressed();
}
但是这段代码会破坏回收器中的最后一个webview。
因此,当我播放第一个webview音频并按下back按钮时,音频仍在后台播放,而当我播放最后一个音频(webview)时,它会在调用Backpress时停止。
所以我需要销毁recyclerview中的所有webview。
但我不知道怎么
public void destroyWebView() {
if(videoWebView != null) {
videoWebView.loadUrl("");
videoWebView.loadData("", "text/html" , "utf-8" );
videoWebView.clearHistory();
// NOTE: clears RAM cache, if you pass true, it will also clear the disk cache.
// Probably not a great idea to pass true if you have other WebViews still alive.
videoWebView.clearCache(true);
// Loading a blank page is optional, but will ensure that the WebView isn't doing anything when you destroy it.
videoWebView.loadUrl("about:blank");
videoWebView.onPause();
videoWebView.removeAllViews();
videoWebView.destroy();
// Null out the reference so that you don't end up re-using it.
videoWebView = null;
}
}
@Override
public void onBackPressed() {
meditationFavSCAdapter.destroyWebView();
super.onBackPressed();
}