Victor Oliveira Victor Oliveira - 24 days ago 11
Android Question

onConfigurationChanged not getting called even with manifest config changes - Why?

I know the question is awful, done thousands of times ; But seriously, I've been stuck for 4 hours trying to solve this. I came into every link from 2009 until today and all of them give the same solution which (**** knows why) is not applying into my case.

This is the activity inside my manifest:

<activity
android:name="com.example.activities.CamerasActivity"
android:configChanges="orientation|screenSize">
</activity>


I'm using SDKs 4.0 or higher:

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />


And this is my class:

public class CamerasActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.cameras_activity);

VideoView videoView = (VideoView)findViewById(R.id.action_cameras);
videoView.setVideoPath("/storage/sdcard/teste.mp4");
videoView.start();
}

//Still not working
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE)
{
Log.d("System.out", "Welcome to Landscape Mode");
}
else if(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT)
{
Log.d("System.out", "Welcome to portrait mode");
}
}
}


When I run my app like this I can see in portrait mode, works fine. if I use
android:screenOrientation="landscape"
on my manifest, I can see forced in landscape mode. This means my layouts are fine but why exactly my
onConfigurationChanged
isn't getting called when I try to rotate the screen? What am I missing?

EDIT:

AVD Config:

enter image description here

Auto-Rotate enabled:
enter image description here

Video the way it is:
enter image description here
And no outputs on my logcat.

Answer

The onConfigurationChanged method is called when you physically rotated an Android device. So, you need to rotate your device to see the method gets called.

Note: The onConfigurationChanged also gets called when you changed locale, etc. See here for more info.

Also, I would have these values for the android:configChanges directive:

android:configChanges="orientation|screenSize|layoutDirection

Also, Issue 61671 might be related to the screen orientation problem described in this post. As of April 2014, this defect / bug has not been resolved by Google.

WORKAROUND

As stated in this SO link, screen orientation might work if the device type is set as a generic 7" tablet instead of Nexus 7.