By default, when the screen orientation has changed at runtime (the user has rotated the device), the activity is shut down and restarted; onDestroy() and onCreate() will be called.
To prevent the activity from being restarted, you can declare a android:configChanges in AndroidManifest.xml File, with "orientation" attribute. onConfigurationChanged() method of your activity will be called, if exist.
example:

Other attributes include :
"mcc", "mnc", "locale", "touchscreen", "keyboard", "keyboardHidden", "navigation", "orientation", "screenLayout", "fontScale", "uiMode".
Details refer: http://developer.android.com/guide/topics/manifest/activity-element.html#config
To prevent the activity from being restarted, you can declare a android:configChanges in AndroidManifest.xml File, with "orientation" attribute. onConfigurationChanged() method of your activity will be called, if exist.
example:

package="com.exercise.AndroidStopOrientationChange"
android:versionCode="1"
android:versionName="1.0">
android:label="@string/app_name"
android:configChanges="orientation">
package com.exercise.AndroidStopOrientationChange;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.Toast;
public class AndroidStopOrientationChange extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(AndroidStopOrientationChange.this,
"onCreate()",
Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(AndroidStopOrientationChange.this,
"onDestroy()",
Toast.LENGTH_SHORT).show();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Toast.makeText(AndroidStopOrientationChange.this,
"onConfigurationChanged(): " + newConfig.toString(),
Toast.LENGTH_SHORT).show();
}
}
Other attributes include :
"mcc", "mnc", "locale", "touchscreen", "keyboard", "keyboardHidden", "navigation", "orientation", "screenLayout", "fontScale", "uiMode".
Details refer: http://developer.android.com/guide/topics/manifest/activity-element.html#config