Occasionally, you may want to make sure that your application is displayed in either landscape or Landscape mode in a certain direction. For example, you may develop a game that runs only in Landscape mode. In this case, you can write code to force the direction of the activity to be set to horizontal, which requires the setrequestorientation () method of the activity class. [Java] view plaincopyimport android. content. PM. activityinfo; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // setrequestedorientation (activityinfo. screen_orientation_landscape);} to set it to portrait mode, you can use activityinfo. screen_orientation_portrait constant. In addition to the setrequestorientation () method, you can also set it in the androidmanifest. xml file. [HTML] view plaincopy <? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "net. learn2develop. orientations "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 14 "/> <application Android: icon = "@ drawable/ic_launcher" Android: Label = "@ string/app_name"> <activity Android: Label = "@ string/app_name" Android: Name = ". orientationsactivity "<! -- Set screenorientation --> Android: screenorientation = "Landscape"> <intent-filter> <action Android: Name = "android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity> </Application> </manifest> in the previous example, the contained activity is set to Landscape mode, the activity is also blocked from being destroyed. This is because the activity is set to a fixed direction. When the device direction changes, the activity will not be destroyed, and the oncreate () method will not be called. The following two values are available for the Android: screenorientation attribute: Portrait -- portrait Mode Sensor -- determines the direction based on the gravity Tester (default)