As I said in this thread, I want my WebView to not allow a web page to reload when another action comes to the fore, or just when the orientation changes. The reason is that WebView content is generated almost entirely by Javascript / AJAX. After searching several forums, I found out that many people suggested using the "saveState" and "restoreState" methods, but when I look at the documentation, it says:
Note that this method no longer restores display data for this WebView. See SavePicture (Bundle, File) and restorePicture (Bundle, File) for saving and restoring displayed data.
So here I used this savePicture and restorePicture as follows:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
... some other lines ....
setContentView(R.layout.main); mWebView = (WebView) findViewById(R.id.webview); if (savedInstanceState == null){ loadInicialWebUi(); }else{ mWebView.restoreState(savedInstanceState); boolean restoredPic = mWebView.restorePicture(savedInstanceState, new File("savedDisplayWebView.temp")); Log.d(TAG, "restored Picture:" + restoredPic); } } @Override protected void onSaveInstanceState(Bundle savedInstanceState) { mWebView.saveState(savedInstanceState); boolean savedPic = mWebView.savePicture(savedInstanceState, "savedDisplayWebView.temp"); Log.d(TAG, "saved Picture:" + savedPic); super.onSaveInstanceState(savedInstanceState); }
And well, these magazines showed that he was saving the image, but he could not restore it. I suspect there might be something in the file links, but I could not think of a better way to get a link to the file I created while maintaining the state.
Is anyone thrilled? I would appreciate any tips / suggestions. Thanks in advance.
Manuel
android webview android-webview
mdelolmo
source share