Skip to content Skip to sidebar Skip to footer

White Screen After Closing Fullscreen Video Opened From Webview

I have a WebView with embedded youtube video. I've implemented fullscreen mode using simple dialog solution like this: webView.setWebChromeClient(new CustomWebChromeClient()); pub

Solution 1:

Did some digging into android code and found the solution:

publicclassCustomWebChromeClientextendsWebChromeClient {

    @OverridepublicvoidonShowCustomView(View view, final CustomViewCallback callback) {
        Dialogdialog=newDialog(ArticleDetailsActivity.this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        view.setBackgroundColor(getResources().getColor(R.color.black));
        dialog.setContentView(view);
        dialog.setOnDismissListener(newDialogInterface.OnDismissListener() {
            @OverridepublicvoidonDismiss(DialogInterface dialog) {
                callback.onCustomViewHidden();
                chromeWebClient.onHideCustomView();
            }
        });
        dialog.show();
    }

    @OverridepublicvoidonHideCustomView() {
        super.onHideCustomView();
    }
}

CONNECTED ISSUE - SOLVED: Turns out this crashes sometimes with HTML5VideoView.reprepareData when reopening the activity and playing the video again or HTML5VideoView.isPlaying when calling webView.onPause() which seems to be another issue...

FINAL NOTE

In order to WebView work well and not leaking memory you should call respective WebViewMethods in Activity or Fragment lifecycle callbacks as following for the Activity (probably somehow similar for the Fragment):

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        webView.restoreState(savedInstanceState);
    } 
}

@OverrideprotectedvoidonSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(BundleKeys.HAS_PHOTOS, hasPhotos);
    outState.putLong(BundleKeys.ARTICLE_ID, articleId);
    webView.saveState(outState);
}

@OverrideprotectedvoidonResume() {
    webView.onResume();
}

@OverrideprotectedvoidonPause() {
    super.onPause();
    webView.onPause();
}

@OverrideprotectedvoidonStop() {
    super.onStop();
    webView.stopLoading();
}

@OverrideprotectedvoidonDestroy() {
    super.onDestroy();
    webView.destroy();
}

Post a Comment for "White Screen After Closing Fullscreen Video Opened From Webview"