2014-01-23 193 views
1

旋转时出现问题。不希望的OnCreate再次运行旋转问题Android

这是代码 ---->清单

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18"/> 

---->清单

<activity 
    android:name=".actManten" 
    android:label="Correctivo" 
    android:configChanges="keyboard|keyboardHidden|orientation"> 
</activity> 

---->活动

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
} 

请帮帮我

回答

1

1 -您可以通过在manifest中将android:screenOrientation="portrait"(或"landscape")添加到<activity>来锁定某个方向的活动。

2 -你可以告诉你的意思是通过在<activity>标签指定android:configChanges="screenOrientation"来处理自己的屏幕变化的系统。这样,活动将不会被重新创建,但会收到一个回调(您可以忽略,因为它对您没有用处)。

就我个人而言(2)。当然,如果将应用程序锁定在其中一个方向上并没有问题,那么也可以使用(1)。

根据您所选择的选项,你的活动应该声明如下:

<activity 
    android:name=".actManten" 
    android:label="Correctivo" 
    android:screenOrientation="portrait" 
    android:configChanges="keyboard|keyboardHidden|orientation"> 
</activity> 

2-

<activity 
    android:name=".actManten" 
    android:label="Correctivo" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenOrientation"> 
</activity> 

为笔记Android 3.2+(API 13) - 从此版本开始,屏幕旋转也会导致屏幕大小发生变化l刷新UI。您需要声明“orientation|screenSize”而不是“orientation”。 http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

+0

您好,感谢 尝试添加清单 screenOrientation b ut我得到错误 错误:错误:字符串类型不允许(在'configChanges'值'keyboard | keyboardHidden |定位| screenOrientation')。 –

+0

@ user2493770你在那个应用上使用了android api版本? –

+0

嗨,谢谢.. 我正在使用的版本 Android 2.3.3 api等级10 帮我 –

0

按照Android docs for the configChanges attribute

Note: If your application targets API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), then you should also declare the "screenSize" configuration, because it also changes when a device switches between portrait and landscape orientations.

你应该改变

android:configChanges="keyboard|keyboardHidden|orientation" 

android:configChanges="keyboard|keyboardHidden|orientation|screenSize" 
+0

您好,感谢 尝试添加清单 屏幕尺寸 但我得到错误 错误:错误:字符串类型不允许(在“configChanges”,值为“键盘| keyboardHidden |方向| 屏幕尺寸”)。 –