问题描述
我有两个活动,我使用android:configChanges =keyboardHidden |方向|屏幕尺寸
I have two activities and I use the android:configChanges="keyboardHidden|orientation|screenSize"
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.activity_main);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
}
}
一个积极运用肖像的第二横向但是当方向改变,活动加载和数据丢失
One active use for portrait to landscape orientation of the secondbut when the orientation changes, activity is loaded and data is lost
我怎么能保存数据并更改活动的方向?
推荐答案
如果您有较少的数据,你可以保存和使用得到它 onSavedInstanceState
和 onRestoreInstanceState
..对deatils通过这个链接保存数据
If you have a less data you can save and get it using onSavedInstanceState
and onRestoreInstanceState
.. for deatils go through this link Saving data
但柜面你有大量的数据,那么我必须说,你不应该允许方向变化,你可以通过添加下面的清单文件行限制的:
But incase you have large data then I must say you should not allow for the orientation changes you can restrict it by adding below line in manifest file :
android:configChanges="orientation|keyboardHidden" // fixes orientation
这篇关于保存数据和改变方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!