Android how to prevent restart the activity on orientation change.

For manual orientation change:

[php]
<activity
android:name=".ActivityName"
android:configChanges="orientation"/>
[/php]

[php]

public class ActivityName extends Activity {

onStart() {
setRequestedOrientation(orientation);
}
onConfigurationChanged(Configuration newConfig){
// do stuff for orientation change.
}
onClick() {
setRequestedOrientation(orientation);
}
}

[/php]

For auto-orientation detect:

[php]
<activity
android:name=".ActivityName"
android:configChanges="orientation"/>

[/php]

[php]

public class ActivityName extends Activity {

onConfigurationChanged(Configuration newConfig){
// do stuff for orientation change.
}
}
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *