简体   繁体   中英

Is android WebView saveState/restoreState broken in 4.0+

I have implemented the webview saveState() restoreState() logic to restore a webview's current page and history like so:

public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    ...

    if(savedInstanceState != null)
    {
        webView.restoreState(savedInstanceState);
    }
    else
    {
        webView.loadUrl(url);
    }
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    if(webView != null) webView.saveState(outState);
}

I'm testing state saving by killing the app process via DDMS while the app is in the background.

When relaunching the app it is working as expected on 2.x devices but doesn't on 4.x devices. Instead I either get a blank webview or oddly, the display of the first page in the history.

Has anyone experienced 4.x specific issues with webview?

Solved the problem.

Save/restore aren't the issue, turns out the problem was with the specific URLs I was loading. They included a hash symbol which run afould of this bug in 3.0+ : Issue Details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM