0

I am using Android Webview to load some web content into my app. The loading page has some Javascript content, so I have to set the ' webSettings.setJavaScriptEnabled(true)" as true, the problem is when i click back from the webpage whole phone screen turns to white blank screen.

I found one more thing is if i set webSettings.setJavaScriptEnabled(false) the webview loads the page successfully, but not fully shows the content as expected. I am using the Code below. How can i get rid of this issue ? Searched so many places and couldn't find any helpful answer.

  private void initView() {
    initWebView();
    initWebSettings();
}

@SuppressLint("NewApi")
private void initWebView() {
    setWebChromeClient(new WebChromeClientCustom());
    setWebViewClient(new WebViewClientCustom());
    setOnLongClickListener(this);
    setFocusableInTouchMode(true);
    requestFocus();
}

@SuppressLint("SetJavaScriptEnabled")
private void initWebSettings() {
    final WebSettings webSettings = getSettings();
    webSettings.setUseWideViewPort(false);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setSupportMultipleWindows(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
    webSettings.setAppCacheEnabled(true);
}
Faizal Malik
  • 197
  • 3
  • 11

1 Answers1

0

If you want to close Activity that holds WebView when back pressed, you can override onBackPressed method and close the activity:

@Override
public void onBackPressed() {
    finish();
}
Natig Babayev
  • 3,128
  • 15
  • 23
  • I am using fragment to load the webview, but there is no problem if i set the setJavaScriptEnabled as false. So i hope its someting releated to web settings – Faizal Malik Feb 14 '18 at 11:31