问题描述
我有3个标签一tabhost。在每个选项卡中有一个webiview。当我点击一个选项卡中的web视图需要刷新,甚至当我到了那里之前,尚未保存。有没有什么办法可以挽救的WebView?
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 ?
推荐答案
这可以通过在活动overrwriting的onSaveInstanceState(捆绑outState)和web视图调用saveState和处理:
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);
}
然后恢复这在你的onCreate后的WebView已经重新充气课程:
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)
}
您可以参考此<一个href="http://www.devahead.com/blog/2012/01/$p$pserving-the-state-of-an-android-webview-on-screen-orientation-change/">LINK
这篇关于Android的web视图saveState和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!