sandalone
sandalone

Reputation: 41749

How return to webview's cached page?

I am using a webview to load a remote mobile-optimized webpage (like m.mysite.com). The site uses jquery to load next 10 articles. I mean, by default only 10 articles are visible and on the bottom there is a button "load more". When a user presses it, it loads next 10 articles, and so on.

Now, when I load next 10 articles and want to read 15th or 16th article (just an example), the webview loads the article itself. but when I return via mobile Back button, the webview does not load to 15th or 16th article, but it reloads the page and I find myself on article 1 (e.g. it loads the default URL with first 10 articles only).

I tried this in the PC web browser, and it works fine in such browser.

How can I force webview to load the page from the cache, and not to reload it?

I use the usual code for back button:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the BACK key and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
        webView.goBack();
        return true;
    }

    return super.onKeyDown(keyCode, event);
}

//gives the same problems
//    @Override
//    public void onBackPressed() {
//        super.onBackPressed();
//        webView.goBack();
//    }

Upvotes: 2

Views: 1676

Answers (1)

Nuno
Nuno

Reputation: 3612

I found your question here, and saw it has no answer.

I am currently looking for the same thing, and I found this while researching and I am going to try it out: http://alex.tapmania.org/2010/11/html5-cache-android-webview.html

This should enable Cache on your webview. It's a matter of just copy and paste what is on the link above.

If you only want cache in the Back button, probably just keep it disabled and enable it when Back button is pressed?

Hope this helps you.

Upvotes: 1

Related Questions