如何保存和保存恢复Webview状态?

编程入门 行业动态 更新时间:2024-10-28 21:14:26
本文介绍了如何保存和保存恢复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 从来都不可靠.这也许就是为什么文档现在这样说的原因.

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状态?

本文发布于:2023-10-26 11:32:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530012.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:状态   Webview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!