Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android onConfigurationChanged() is not being called in Activity

I realize that there are a couple other posts on this topic, however the solutions for those posts are not working for me.

Basically, I want to cease my Activity from restarting upon a device orientation change. To do this, I have modified the activity in the manifest file:

        <activity android:name=".MyActivity" android:configChanges="orientation|keyboardHidden"></activity>

and I have overridden onConfigurationChanged() in my Activity:

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

    System.out.println("IN onConfigurationChanged()");
}

However, the activity is still restarting upon an orientation change, and the onConfigurationChanged() method is not being called.

Does anyone know why this may be happening?

like image 966
littleK Avatar asked Jun 15 '11 14:06

littleK


2 Answers

You should use 13 API and set this configuration in your activity's part of the manifest: android:configChanges="orientation|keyboardHidden|screenSize"

It works fine. At all Android version.

like image 50
leonvian Avatar answered Sep 26 '22 01:09

leonvian


Change your manifest to following

<activity android:name=".MyActivity" android:configChanges="orientation|keyboardHidden|screenSize"></activity>

and refer this link for detailed explanation orientation issue

like image 24
Avinash Agrawal Avatar answered Sep 23 '22 01:09

Avinash Agrawal