I searched a lot of threads and still can not find the answer to my question. I am working on an Android application that uses WebView .
I use onSaveInstanceState() and onRestoreInstanceState() to save the state of the WebView as follows:
@Override public void onSaveInstanceState(Bundle savedInstanceState) { webView.saveState(savedInstanceState); }
and
@Override public void onRestoreInstanceState(Bundle savedInstanceState) { webView.restoreState(savedInstanceState); }
I also have this in my onCreate() :
public void onCreate(Bundle savedInstanceState) { ... other code ... if(savedInstanceState != null){ webView.saveState(savedInstanceState); }else{ webView.loadUrl("http://mypage"); } }
Problem: Restoring WebView does not seem to restore Javascript variables / environment / workspace at all. When the application is killed in the background and then restored, all Javascript is gone with all objects / variables. The javascript code is exploded by name, i.e. window.utilitiesPack , window.eventHandlers , window.automation , etc., and they are undefined. JQuery and other javascript plugins are also used: they all look undefined after a recovery state. Basically, all Javascript is not restored.
Can someone confirm or deny that it is so (Javascript is not saved)? If the entire Javascript workspace is not saved, then what exactly does WebView.saveState() save? Is there a simple / elegant way to use an existing API to save Javascript objects?
// ================================================== ======
Update1: So the problem remains. The most significant problem is the following:
I run Camera Intent for the result. When the snapshot is taken, the application returns to WebView activity and is supposed to use Javascript to update HTML5 LocalStorage with some data variables.
The main action with WebView will be killed when the camera activity is displayed, so when we return to WebView, there will be no more Javascript and there are no functions that I can call from Android code. This happens every time on the Galaxy S3 . This still happens on other phones, but not every time when shooting.
I donβt know what to do here. Somehow I have to do the main Activity with a WebView in order to maintain a state when the image is executed using the cameraβs intent. Does anyone know how this can be achieved?