Android webView 保存状态

Android webView saveState(Android webView 保存状态)

本文介绍了Android webView 保存状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 3 个标签的标签主机.在每个选项卡中都有一个 webiview.当我单击一个选项卡时,即使我以前去过那里,webview 也需要重新加载",它还没有被保存.有什么办法可以保存 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 ?

推荐答案

这可以通过在您的活动中覆盖 onSaveInstanceState(Bundle outState) 并从 webview 调用 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);
    super.onSaveInstanceState(outState); 
}

当然,在 webview 重新膨胀之后,在你的 onCreate 中恢复它:

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)
}

这篇关于Android webView 保存状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Android webView 保存状态

基础教程推荐