No screen rotation changes with phone
Sometimes we want to keep the interface of a program in one direction and not in the direction of the phone: add android:screenorientation to every activity configuration in Androidmanifest.xml that requires no steering = "Landscape" property.
Landscape = Transverse portrait = Portrait
Avoid restarting activity when you turn the screen
The activity is restarted every time the screen orientation is switched on Android, so you should save the current active state before the activity is destroyed and load the configuration when the activity is re-create, so that the in-progress game will not restart automatically! To avoid restarting the activity when you turn the screen, you can redefine the direction in the Androidmanifest.xml file by adding android:configchanges= to each activity keyboardhidden| Orientation " property). Override the onconfigurationchanged (Configuration newconfig) method in the activity where you want to control the display direction of the screen so that the activity does not restart when you turn the screen.
if (newconfig.orientation==configuration.orientation_landscape) { // landscape Else// Vertical Setcontentview (r.layout.file_list);}
<ActivityAndroid:name= "Com.myapp.MyActivity"Android:label= "@string/app_name"Android:screenorientation= "Landscape"Android:configchanges= "orientation" > intent-filter> <action android: Name= "Android.intent.action.VIEW" /> <category android:name = "Android.intent.category.DEFAULT" /> </intent-filter> </activity>
android:screenorientation= "Landscape" android:configchanges= "keyboardhidden|orientation"
@Overridevoid onconfigurationchanged (Configuration newconfig) { Superif ( newconfig.orientation==// landscape Else// vertical Setcontentview (r.layout.file_list);}}
In the simulator you can do screen rotation by CTL+F11 simulation.
Disable screen rotation and restart activity in Android programs