如何保存和保存恢复Webview状态? [英] how to save & restore Webview State?

查看:210
本文介绍了如何保存和保存恢复Webview状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用备份&恢复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 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状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆