如何保存的WebView当屏幕方向改变 [英] How save WebView when screen orientation was changed
问题描述
在我的应用程序用于载入index.html的唯一的WebView在那里运行所有应用逻辑(HTML的和JavaScript)。
In my application I use only WebView for loading index.html where running all app logic(html's and javascript).
当屏幕方向改变,从JavaScript变量的所有数据消失。
Where screen orientation changed, all data from JavaScript variables disappear.
我如何保存所有数据时,方向改变?
How I can save all data when orientation changed?
推荐答案
您必须赶上取向的变化和自己,处理它们,因为默认情况下,活动被重新创建(和你的WebView将重新加载)。
You have to catch orientation changes and handle them by yourself, because by default the Activity gets recreated (and your WebView will be reloaded).
添加 的android:configChanges
属性在AndroidManifest.xml你的活动
Add the android:configChanges
attribute to your Activity in the AndroidManifest.xml
<activity ... android:configChanges="orientation|keyboardHidden|keyboard">
和覆盖你的Activity类中的 onConfigurationChanged
方法。
And override the onConfigurationChanged
method in your Activity class.
@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
也看看这里:活动重新开始轮换的Android
这篇关于如何保存的WebView当屏幕方向改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!