1

I have an activity A which has a button. On clicking this button, activity B launches. Activity B has WebView inside an xml layout which loads HTML page stored locally on the device. The whole webpage consist of several CSS(heavy material) and jsons(large in size). At this time the RAM usage is around 90MB. HTML have input fields both text and numeric in it. The problem is after opening and closing the webview 3-4 times, when I click on the input field the keyboard become invisible.

Click here for screenshot

This is my activity code.

public class LaunchActivity extends Activity {

WebView webView;
private final int FILECHOOSER_RESULTCODE = 1;
private Uri mCapturedImageURI = null;
public String mCameraPhotoPath;
String webViewUrl;
public String mMediaType;
public int flag = 0;
public File imageStorageDir;
Bundle bundle;
String mode;
public ProgressDialog progDailog;

int questionToBeLaunch;

Project project;

public void onBackPressed() {
}

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.launch_survey);

    // getting data from intent and creating the url to load.

    webView = (WebView) findViewById(R.id.webView1);

    setWebViewProperties();

    Map<String, String> header = new HashMap<String, String>(2);
    header.put("Pragma", "no-cache");
    header.put("Cache-Control", "no-cache");
    webView.loadUrl(webViewUrl, header);
}

public void setWebViewProperties(){
    JavaScriptInterface jsInterface = new JavaScriptInterface(this);
    // Javascript enabled on webview
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAllowUniversalAccessFromFileURLs(true);


    webView.addJavascriptInterface(jsInterface, "interface");

    // Other webview options
    webView.getSettings().setLoadWithOverviewMode(true);

    //webView.getSettings().setUseWideViewPort(true);
    //Other webview settings
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setScrollbarFadingEnabled(false);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setAllowFileAccessFromFileURLs(true);
    webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    webView.getSettings().setSupportZoom(true);

    progDailog = new ProgressDialog(LaunchSurvey.this);
    //Load url in webview
    webView.setWebViewClient(new WebViewClient() {


        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progDailog.setMessage("Loading...");
            progDailog.setCanceledOnTouchOutside(false);
            progDailog.setCancelable(false);
            progDailog.show();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webView.clearCache(true);
        }
    });
}


@Override
protected void onPause() {
    super.onPause();
}


@Override
protected void onDestroy() {
    super.onDestroy();
  //  webView.setOnTouchListener(null);
    webView.removeAllViews();
    webView.clearCache(true);
    webView.clearHistory();

   // clearCache(getApplicationContext());
    webView.destroy();
    webView = null;
}
}
Ankit Singh
  • 121
  • 7

1 Answers1

0

After struggling for many days, finally I figured out the root cause of your problem. It is probably because of the heavy javascript code that webview needs to parse. Try to lighten it a bit and you are all set, the numeric keypad won't get invisible.

Rojy Kumari
  • 159
  • 11