[英]Why my list reload after my pop up finished?
I have a list which contains images.I put a method every image which is open popup ( I mean I use android:theme="@android:style/Theme.Dialog" in manifest.xml
) and when I click my image my new activity opens. 我有一个包含images.I的方法列表每个图像都打开弹出窗口(我的意思是我android:theme="@android:style/Theme.Dialog" in manifest.xml
使用android:theme="@android:style/Theme.Dialog" in manifest.xml
)当我点击我的图像我的新活动开始了。 For now evething works fine. 现在evething工作正常。
My first activity : I use this : setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
我的第一个活动:我使用它: setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
On my popup activity : I use this: setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
在我的弹出活动中:我使用: setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
When I click image and open popup , yes the screen rotate and become lanscape and when I back button my screen rotate again and but the problem is : when I back my main activity and when roate again to portrait the list is reload again, I do not know why it is? 当我点击图像并打开弹出窗口时,是的,屏幕旋转并成为景观 ,当我返回按钮时,我的屏幕再次旋转,但问题是:当我支持我的主要活动,当再次漫游到肖像时,列表再次重新加载,我做不知道为什么会这样?
And is it possible to I do not want to rotate my first screen with the popup activity? 我是否有可能不想使用弹出活动旋转我的第一个屏幕? thanks 谢谢
Your list is reloading because the activity is destroyed and re-created when the orientation changes. 您的列表正在重新加载,因为活动在方向更改时被销毁并重新创建。 The simplest thing is to manually handle orientation changes in the activity - and do nothing about it. 最简单的方法是手动处理活动中的方向变化 - 并且不做任何事情。 Also, you can specify the portrait or landscape for an activity in the Manifest. 此外,您可以在Manifest中为活动指定纵向或横向。 Your manifest would then contain something like this: 您的清单将包含以下内容:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:allowBackup="true"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="sensorPortait"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PreviewActivity"
android:screenOrientation="sensorLandscape"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation"
android:theme="@android:style/Theme.Dialog"
android:excludeFromRecents="true" >
</activity>
...
</application>
Note the lines android:configChanges
in the declaration of each activity. 注意每个活动的声明中的android:configChanges
行。 Also note the lines android:screenOrientation
- with these lines added you don't need to call setRequestedOrientation
in the code. 还要注意android:screenOrientation
的行 - 添加这些行后你不需要在代码中调用setRequestedOrientation
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.