0

活动的manaifest.xml如下:

<activity
    android:name="com.wd.wuc.SearchStatusActivity"
    android:label="@string/app_name"
    android:screenOrientation="sensor"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    android:configChanges="orientation|keyboard"  >
</activity>

Activity的代码如下:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_status);
    System.out.println("onCreate!!");
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    System.out.println("onConfigurationChanged!!");
}

当我改变方向时,我想运行 onConfigurationChanged。
但是代码只运行onCreate方法,而不运行onConfigurationChanged。
我该如何修改它?

4

4 回答 4

5

在文档(http://developer.android.com/guide/topics/manifest/activity-element.html)中,您可以找到:

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.

如果您的目标是 API 13 或更高版本,您应该尝试将“|screenSize”添加到 configChanges:

android:configChanges="orientation|keyboard|screenSize"
于 2013-08-05T06:28:01.117 回答
1

Replace

android:configChanges="orientation|keyboard"

with

android:configChanges="orientation|keyboardHidden"

in your manifest file.

Look this for your reference.

于 2013-08-05T06:37:52.100 回答
1

android:configChanges="orientation|keyboard"

此行告诉 Dalvik 编译器您正在处理键盘和方向的更改。所以请删除此行,它肯定会起作用。

于 2013-08-05T06:26:21.443 回答
0

从清单文件中删除这个标签。然后它会工作

android:configChanges="orientation|keyboard"
于 2013-08-05T06:24:11.130 回答