Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android webView saveState

Tags:

I have a tabhost with 3 tabs. In each of these tabs there is a webiview. When i click a tab the webview need to "reload" even when i have been there before, it have not been saved. Is there any way to save the webview ?

like image 338
Ukjent Avatar asked Apr 21 '12 12:04

Ukjent


People also ask

Is Android WebView deprecated?

This interface was deprecated in API level 12. This interface is now obsolete.

How do I enable JavaScript on WebView?

JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.

What does Android WebView mean in Google Analytics?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.


1 Answers

This can be handled by overrwriting onSaveInstanceState(Bundle outState) in your activity and calling saveState from the webview:

@Override protected void onSaveInstanceState(Bundle outState) {     webView.saveState(outState);     super.onSaveInstanceState(outState);  } 

Then recover this in your onCreate after the webview has been re-inflated of course:

@Override public void onCreate(final Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.blah);    WebView webview = (WebView)findViewById(R.id.webview);    if (savedInstanceState != null)       webview.restoreState(savedInstanceState);    else       webview.loadUrl(URLData) } 
like image 72
Shankar Agarwal Avatar answered Sep 20 '22 12:09

Shankar Agarwal