开发者

application restarting when changing orientation even after locking in android

I want to prevent my application from restarting when orientation of device changes. I have lock the app orientation as per below code but it doesn't help 开发者_开发问答for the same.

<activity android:name=".CheckMemory"
    android:configChanges="orientation"
    android:screenOrientation="portrait"
    android:theme="@style/customTheme"
              android:label="@string/app_name">

    </activity> 

and

@Override
    public void onConfigurationChanged(final Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    //Do nothing here
    }


I did below and works well.

<activity android:name=".CheckMemory"
        android:configChanges="orientation"
        android:screenOrientation="portrait"
        android:theme="@style/customTheme"
                  android:label="@string/app_name">

        </activity> 

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


First of all, remember that screen orientation is defined per activity. So if you have other Activities than CheckMemory, they will still respond to a change in orientation. You need to define android:screenOrientation for all your Activities.

Secondly, you seem to be calling super.onConfigurationChanged(newConfig), will this not just do what the system will normally do? Try to remove that line and really leave the method empty (really do nothing).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜