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


Last Updated: 2011-07-30 12:46:08
  1. vovs

    vovs Active Member

    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 (Text):
    1. public void onCreate(Bundle savedInstanceState) {
    2.         super.onCreate(savedInstanceState);
    3.         setContentView(R.layout.main);
    4.         url = getPrefProperty(this, CURRENT_URL);
    5.         if(TextUtils.isEmpty(url)){
    6.             //show dialog here
    7.             //getting here url and calling mWebView.loadUrl(url);          
    8.         }
    9.         mWebView = (WebView) findViewById(R.id.webview);
    10.         if (savedInstanceState != null){
    11.             ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
    12.         } else {            
    13.             mWebView.getSettings().setJavaScriptEnabled(true);
    14.             mWebView.getSettings().setPluginsEnabled(true);
    15.             mWebView.getSettings().setSupportZoom(false);
    16.             mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
    17.             mWebView.setWebViewClient(new ManWebViewClient());
    18.             //if(!TextUtils.isEmpty(url)) mWebView.loadUrl(url);
    19.         }
    20.     }
    21.  
    22.     protected void onSaveInstanceState(Bundle outState) {
    23.         mWebView.saveState(outState);
    24.      }
    25.  
    26.     @Override
    27.     protected void onRestoreInstanceState(Bundle state) {
    28.         mWebView.restoreState(state);
    29.         super.onRestoreInstanceState(state);
    30.         //Toast.makeText(getBaseContext(), browser.getUrl(), Toast.LENGTH_LONG).show();
    31.     }
    32.  
    33.     private class ManWebViewClient extends WebViewClient {
    34.         @Override
    35.         public boolean shouldOverrideUrlLoading(WebView view, String url) {
    36.             view.loadUrl(url);
    37.             return true;
    38.         }
    39.     }

    Advertisement

Share This Page