Tom McFarlin
Tom McFarlin

Reputation: 829

WebView not reflecting changes on server until clearing data

I found an interesting bug that I can not replicate, but think someone here could provide some insight.

I have an activity that for now is partially native, partially web-based. By that I mean one element is simply a WebView until implementation on a native level can be achieved.

When I made a change in the page I am loading, I saw an immediate change using Chrome Developer Tools in a mobile interface. However, I was unable to immediately see the change in my WebView in my MainApp. As a test, I installed a new app that loaded the page in a WebView where I saw the changes. After clearing the data in my MainApp, I was able to see said changes.

I made a few more changes, but now these are being reflected immediately in my WebView (upon backing out of the activity and re-entering).

These are my WebView settings, can you see a reason for me not initially seeing these changes? I'm not very savvy (yet :) ) when dealing with how data is stored in a WebView and want to ensure that updates I make to my webpage are reflected immediately in the app. Thank you!

// Initialize WebView
    if (Build.VERSION.SDK_INT >= 19)
        mWebView.setWebContentsDebuggingEnabled(false);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);

            // Hide ProgressBar
            mProgressBar.setVisibility(View.GONE);
        }
    });
    final ActionBarActivity activity = this;
    mWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            // Activities and WebViews measure progress with different scales.
            // The progress meter will automatically disappear when we reach 100%
            mProgressBar.setProgress(progress);
        }
    });

    // Settings for WebView data
    WebSettings ws = mWebView.getSettings();
    ws.setSaveFormData(false);
    ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecated)

Upvotes: 0

Views: 1013

Answers (2)

Nawin
Nawin

Reputation: 636

In case if you want to reload the the webview every time when you reopen.

use this setting for webview

webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

This will not load the cache and the requirement will get fulfilled.

Upvotes: 0

Jonas Czech
Jonas Czech

Reputation: 12348

You probably need to disable the cache for your webview. When your data changes you need to reload the webview using mWebView.reload()

Upvotes: 1

Related Questions