简体   繁体   English

Android Webviews,在更改活动时保存状态?

[英]Android Webviews, saving the state when changing activity?

I have a number of different webviews, all in their own activity. 我有许多不同的Web视图,它们都在自己的活动中。

When a menu item is pressed a new activity loads and so does it's webview. 当按下菜单项时,将加载一个新的活动,并且它是webview。

Now clicking between activities reloads each webview, is there a way so that when changing activities the web page doesn't reload and it remembers where the user was? 现在,在活动之间单击可以重新加载每个Web视图,有没有一种方法可以使在更改活动时不重新加载网页,并且记住用户所在的位置?

Thanks 谢谢

You can use WebView method saveState()/restoreState() and save it to activity onRestore bundle and use saved value in onCreate method if the previous Activity will be destroyed. 您可以使用WebView方法saveState()/ restoreState()并将其保存到活动onRestore捆绑包中,如果先前的活动将被销毁,请在onCreate方法中使用保存的值。
You can use similar method which is described here (but used for only configuration change): 您可以使用此处描述的类似方法(但仅用于配置更改):
http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/ http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM