如何在$设备方向变化p $ pvent活动启动仅适用于一些时间,而不是所有的时间 [英] How to prevent activity restart on device orientation change only for some duration and not all the time
问题描述
在我的活动中,有很多处理的OnCreate中进行()就像打开一个数据库,在SD卡上写入文件。但是,所有这些沉重的处理只发生一次活动时推出了第一次,之后不会。我使用的是异步任务来实现这一目标。
In my activity, there is a lot of processing done in oncreate() like opening a database, writing files on the sd card. But all of this heavy processing happens only once when the activity is launched the first time and not after that. I am using an Async task to achieve this.
我使用的过程中设备配置变化如下code至prevent活动重新开始。
I am using the following code to prevent activity restart during device configuration change.
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
我想禁用到期时的初始设置发生后,我想使活动在重启设备的方向改变一次活动重新开始。任何想法我如何能做到这一点?
I wish to disable activity restart due to change in device orientation only once when the initial setup takes place and after that, I want to enable activity restart. Any idea how I can achieve this?
推荐答案
这添加到清单文件中的活动标签
add this to your activity tag in manifest file
安卓configChanges =方向| keyboardHidden
android:configChanges="orientation|keyboardHidden"
这篇关于如何在$设备方向变化p $ pvent活动启动仅适用于一些时间,而不是所有的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!