Disable screen rotation and restart Activity in android Program
Disable screen rotation with mobile phone
Sometimes we want to keep the interface of a program in one direction and not change with the orientation of the mobile phone:
In AndroidManifest. xml, addAndroid: screenOrientation = "landscape"Attribute.
Landscape = landscape
Portrait = portrait
Avoid restarting the Activity during screen conversion.
In android, the Activity is restarted every time the screen direction is switched. Therefore, you should save the status of the current Activity before the Activity is destroyed and load the configuration when the Activity is created again, in progress, the game will not automatically restart!
To avoid restarting the Activity during screen conversion, you can re-define the direction in the AndroidManifest. xml file (add the android: configChanges = "keyboardHidden | orientation" attribute to each Activity ).
Rewrite the onConfigurationChanged (Configuration newConfig) method in the Activity that needs to control the display direction of the screen, so that the Activity will not be restarted during screen conversion.
@ Overridepublic void onConfigurationChanged (Configuration newConfig) {super. onConfigurationChanged (newConfig); if (newConfig. orientation = Configuration. ORIENTATION_LANDSCAPE) {// transverse setContentView (R. layout. file_list_landscape);} else {// vertical setContentView (R. layout. file_list );}}
In the simulator, screen rotation can be simulated by CTL + F11.