1

I am trying to implement a WebView activity everything works fine but if the app is idle for 30 min and opens again and clicks on any link it opens in browser and it don't do same behavior in all the SDK majorly Lollipop

following is the code I have used and I have also used shouldOverrideUrlLoading

private void startWebView(String url) {
        webView.setWebViewClient(new WebViewClient() {

            ProgressDialog progressDialog;

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

            public void onLoadResource(WebView view, String url) {
                getBaseContext();
                if (progressDialog == null) {
                    progressDialog = new ProgressDialog(MainActivity.this);
                    progressDialog.setMessage("Loading...");
                    //progressDialog.show();
                }
            }

            public void onPageFinished(WebView view, String url) {
                try {
                    CookieSyncManager.getInstance().startSync();
                    CookieSyncManager.getInstance().sync();
                    //ImageView imgView = (ImageView)findViewById(R.id.imageView1);
                    //imgView.setVisibility(View.INVISIBLE);
                    if (progressDialog.isShowing()) {
                        progressDialog.dismiss();
                        progressDialog = null;
                    }

                } catch (Exception exception) {
                    exception.printStackTrace();
                }
            }

            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                startWebView("file:///android_asset/NoInternet.html");

            }
        });
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setRenderPriority(RenderPriority.HIGH);
        webView.getSettings().setPluginState(
                android.webkit.WebSettings.PluginState.ON_DEMAND);
        webView.getSettings().setDatabaseEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
         webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 8);

            webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
            webView.getSettings().setAllowFileAccess(true);
          webView.getSettings().setAppCacheEnabled(true);


        WebView webview = new WebView(this);
        WebSettings ws = webview.getSettings();
        ws.setSaveFormData(true);
        ws.setSavePassword(true );
        webView.loadUrl(url);
        // Log();
    }
Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
Avinash A R
  • 176
  • 2
  • 10
  • try this solution http://stackoverflow.com/questions/21170911/webview-inside-fragment-android-opening-outside-of-the-app-in-a-browser you are not using WebViewClient() – Nanoc Oct 09 '15 at 11:11
  • I have did that in code you can check, by mistake it is came out of code part so above the code part it is there – Avinash A R Oct 09 '15 at 11:38
  • Why are there two webviews ? one seems to be a global variable & another is created inside the 'startWebView()' method. – Code_Yoga Oct 09 '15 at 12:50

0 Answers0