当我使用备份&恢复Webview状态,我收到此消息:x地址处的网页可能暂时关闭或可能已永久移至新的网址.
when i use backup & restore Webview state ,i recive this message : the webpage at x Address might be temporarity down or may have moved permanently to a new web address.
@Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); webViewShowPoll.saveState(savedInstanceState); } @Override public void onRestoreInstanceState(Bundle outState) { super.onRestoreInstanceState(outState); webViewShowPoll.restoreState(outState); }和Androidmanifest.xml
and Androidmanifest.xml
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.SET_DEBUG_APP"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <activity android:name="com.omid.epoll.mobile.Poll" android:launchMode="singleInstance" android:label="@string/title_activity_poll" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> </activity> 推荐答案restoreState 从来都不可靠.这也许就是为什么文档现在这样说的原因.
restoreState was never reliable. That's perhaps why the documentation now says this.
如果在此WebView有机会建立状态后调用它(加载页面,创建后退/前进列表等)可能存在不良的副作用.请注意,此方法不再恢复此WebView的显示数据.
If it is called after this WebView has had a chance to build state (load pages, create a back/forward list, etc.) there may be undesirable side-effects. Please note that this method no longer restores the display data for this WebView.
saveState()的相应条目这样说:
And the corresponding entry for saveState() speaks thus:
请注意,此方法不再存储以下内容的显示数据:此WebView.
Please note that this method no longer stores the display data for this WebView.
如果要显示最后访问的URL,onCreate方法中真正应该做的就是调用webView.loadUrl(),请参阅此答案:
what you really should do inside the onCreate method is to call webView.loadUrl() if you want to display the last visited url, please see this answer:
如果您担心由于方向变化等原因会重新加载Webview.
If you are concerned about the webview reloading on orientation change etc.
您可以将活动"设置为处理方向和KeyboardHidden更改,然后不理会WebView
you can set your Activity to handle the orientation and keyboardHidden changes, and then just leave the WebView alone
更多推荐
如何保存和保存恢复Webview状态?
发布评论