tags:

views:

166

answers:

2

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
    }
A: 

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).

codinguser
Leaving the method empty will cause the system to throw an exception. You can safely just remove the method entirely if you're not doing anything in it.
Christopher
I just do the below and works, don't know how.@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig);}
Maneesh
A: 

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);
}
Maneesh