2

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.

Victor Oliveira
  • 3,293
  • 7
  • 47
  • 77

1 Answers1

2

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.

Community
  • 1
  • 1
ChuongPham
  • 4,761
  • 8
  • 43
  • 53
  • I cant find the settings option on AVD edit and I'm running a quick research to find it; could you edit your answer and post more details about this enable please? thus I can accept the answer – Victor Oliveira Apr 02 '14 at 03:03
  • Inside the AVD is already enabled? did you mean outside on eclipse configs? – Victor Oliveira Apr 02 '14 at 03:07
  • No, I mean inside the AVD. Post your AVD config. Strange that it cannot rotate with CTRL+F11 and screen rotation is enabled in the AVD!... – ChuongPham Apr 02 '14 at 03:09
  • the layout direction didnt work; from where can I retrieve the avd config information? I mean, is there some sort of txt file where everything is up? cause Im looking at ddms perspective and I cant find... – Victor Oliveira Apr 02 '14 at 03:15
  • No, just post a screen dump so I can see what you set for your AVD. Normally, I would have these options for an AVD: **RAM:256**, **VM Heap:64**, **Internal storage:200**, SD Card **Size:50**. And select **Hardware keyboard present** option. – ChuongPham Apr 02 '14 at 03:19
  • From your AVD screenshot, change RAM first to 512 (See the error posted by Android in the screenshot?). Internal storage and SD Card don't need to be 1GB (1,024) - unless your app it's a few hundred megabytes. Also, try turning off the Emulation option to see if it help. – ChuongPham Apr 02 '14 at 03:26
  • Without running your app, when you press Ctrl+F11, does your AVD screen rotate? – ChuongPham Apr 02 '14 at 03:51
  • Now that you mentioned - No, it's not...I believe my settings layout should rotate with CTRL + F11 but it isn't...Browser also doesnt rotate... – Victor Oliveira Apr 02 '14 at 03:55
  • http://stackoverflow.com/questions/19726285/impossible-to-rotate-the-emulator-with-android-4-4 Found this and maybe its the cause – Victor Oliveira Apr 02 '14 at 03:58
  • Issue [61671](http://code.google.com/p/android/issues/detail?id=61671) is similar to your problem. I see the defect is still not completed by Google. – ChuongPham Apr 02 '14 at 04:06
  • Yeah it is and I solved right now, thanks for not give up. Edit your answer please, speak about the bug and to change the run device to a generic tablet from 7" as suggested on the previous link (http://stackoverflow.com/questions/19726285/impossible-to-rotate-the-emulator-with-android-4-4) I gave to you; I really would appreciate to give you those answer points, thank you very much! – Victor Oliveira Apr 02 '14 at 04:08