Skip to content Skip to sidebar Skip to footer

Cannot Load A Webview Inside A Dialogfragment If Previouse Load Didnt Complete The Javascript

I am using a webview inside a dialog fragment. When I press a button the webview is loaded with an URL, than a javascript is run (the javascript takes about 2min, depending on the

Solution 1:

use preViewHtml.stopLoading();,So rewrite your destroy() method as

@OverridepublicvoidonDestroy() {
    super.onDestroy();
    Log.i("DialogFragment", "onDestory");
    preViewHtml.loadUrl("about:blank"); 
    preViewHtml.stopLoading();
    preViewHtml.setWebChromeClient(null);
    preViewHtml.setWebViewClient(null);
    preViewHtml.destroy();
    preViewHtml= null;
} 

also pause and resume webview as

@Override
public void onPause() {
    super.onPause();
    preViewHtml.onPause();
    preViewHtml.pauseTimers(); 
}

@Override
public void onResume() {
    super.onResume();
    preViewHtml.onResume();
    preViewHtml.resumeTimers();
}

Reference : WebView stopLoading()

Post a Comment for "Cannot Load A Webview Inside A Dialogfragment If Previouse Load Didnt Complete The Javascript"