Maneesh
Maneesh

Reputation: 6128

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
    }

Upvotes: 0

Views: 1503

Answers (2)

Maneesh
Maneesh

Reputation: 6128

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

Upvotes: 1

codinguser
codinguser

Reputation: 5572

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

Upvotes: 0

Related Questions