• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps how to save content in webView after minimizing app? and do not reloading after restore app?

Have question: in my app I have one webView. When I minimize application and re-open it - in webview I get white space.

I want when I can minimize application and re-open it without reloading content... code here:

Code:
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        url = getPrefProperty(this, CURRENT_URL);
        if(TextUtils.isEmpty(url)){
            //show dialog here
            //getting here url and calling mWebView.loadUrl(url);           
        }
        mWebView = (WebView) findViewById(R.id.webview);
        if (savedInstanceState != null){
            ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
        } else {             
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.getSettings().setPluginsEnabled(true);
            mWebView.getSettings().setSupportZoom(false);
            mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
            mWebView.setWebViewClient(new ManWebViewClient());
            //if(!TextUtils.isEmpty(url)) mWebView.loadUrl(url);
        }
    } 

    protected void onSaveInstanceState(Bundle outState) {
        mWebView.saveState(outState);
     }

    @Override
    protected void onRestoreInstanceState(Bundle state) {
        mWebView.restoreState(state);
        super.onRestoreInstanceState(state);
        //Toast.makeText(getBaseContext(), browser.getUrl(), Toast.LENGTH_LONG).show();
    }

    private class ManWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones