Hi.
I don't think there is a solution for this.
As you said - reloading a page on orientation change is ok for static webpages but will cause problems with an online game or shopping cart.
There does
seem to be a solution when developing with the Android SDK, look at this example WebView app:
package example.webviewstate;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MyWebView extends Activity {
/** Called when the activity is first created. */
WebView myWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
if(savedInstanceState!=null){
myWebView.restoreState(savedInstanceState);
} else {
myWebView.loadUrl("http://google.co.uk/?q=basic4android");
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState){
myWebView.saveState(savedInstanceState);
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState){
myWebView.restoreState(savedInstanceState);
super.onRestoreInstanceState(savedInstanceState);
}
}
See how the Android SDK gives access to the Bundle 'savedInstanceState'?
It's saved and then restored when the activity is re-created on device orientation change.
So that app loads and displays a Google search for 'basic4android'.
If i click a link in the search results and then rotate my device then the activity is re-created and the WebView loads the last URL i was viewing NOT the original Google search URL.
But i suspect that the WebView re-requests that page when the activity is re-created and so in your situation would have the same problems as using JSInterface in a B4A app to restore the WebView's last state.
If you look at my post here:
http://www.b4x.com/forum/basic4andr.../9400-save-webview-html-file-2.html#post56406.
You can see that you can get the WebView to send the currently displayed page's HTML etc to a B4A Sub once the webpage has loaded.
I wonder if you save that HTML as a String then could you reload that
exact HTML back into the WebView on orientation change using the WebView loadHtml method?
This might work but depends a lot on the content of the webpage - if the webpage contains stuff such as javascript generated elements then simply restoring the webpage HTML would probably not also restore dynamic content.
Martin.