Take the 2-minute tour ×

How would I listen for orientation change in Android? and do certain things when the user has switched to landscape?

share|improve this question

2 Answers 2

up vote 19 down vote accepted

You have a couple of choices:

In your Manifest, put:

<activity android:name=".HelloAndroid"

And, in code, override onConfigurationChanged

public void onConfigurationChanged(Configuration newConfig) {
    // TODO

Here is a good tutorial about it.

share|improve this answer

In your activity, you can override this method to listen to Orientation Change and implement your own code.

public void onConfigurationChanged (Configuration newConfig)

The Configuration Class has an int constant ORIENTATION_LANDSCAPE and ORIENTATION_PORTRAIT, there for you can check the newConfig like this:


int orientation=newConfig.orientation;

switch(orientation) {


//to do something

case Configuration.ORIENTATION_PORTRAIT:

//to do something

share|improve this answer
Huang - your suggestion works well, with one edit. You need to add super.onConfigurationChanged(newConfig); at the beginning of the method to avoid causing an exception. –  Kyle Clegg Nov 21 '11 at 20:11
yes,the super call is neccessary. in eclipse,this line will be automatically added.That's why I omitted. –  Huang Nov 22 '11 at 0:01

Your Answer


