1

I have activity in my application and i have set android:configChanges="orientation" in my menifest file like this :

 <activity
      android:name=".MyActivity"
      android:label="@string/app_name"
      android:configChanges="orientation">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>

and method to handle it :

@Override
  public void onConfigurationChanged(Configuration config) {
    super.onConfigurationChanged(config);
    if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
      Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
  } else if (config.orientation == Configuration.ORIENTATION_PORTRAIT){
      Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
  }
  }

In most google search i saw that it is saying it will prevent restarting my activty but it is starting with orientation changed.I put a System.out.... inside onCreate() it is printing with every orientation change that means it geting started.Any help why it is happening or am i wrong somewhere ?

Android Killer
  • 18,174
  • 13
  • 67
  • 90

1 Answers1

1

Use this in your manifest file.

android:configChanges="orientation|keyboardHidden"

On orientation it will not restart the activity

Abhi
  • 8,935
  • 7
  • 37
  • 60
  • thanks but am not using same thing ? i dont want keyboardhidden attribute so i am not using it. – Android Killer Apr 09 '12 at 10:06
  • it is working.I tried it and it is working.Can you tell me why ? because "KeyBoardGidden" nothing to do with it. right ? – Android Killer Apr 09 '12 at 10:48
  • Please go through [this](http://stackoverflow.com/questions/7818717/why-not-use-always-androidconfigchanges-keyboardhiddenorientation), and you can accept my answer if it works for you – Abhi Apr 09 '12 at 11:01