Android Screen Switch
Android controls the direction of activity, as long as you add a sentence to the corresponding activity node in the Androidmanifest.xml
android:screenorientation= "Landscape" (landscape is horizontal screen, portrait vertical screen).
I have mixed with this sentence for a year, basically all can, but these days I found that this trick is not omnipotent.
The project has a horizontal screen to play the video of the playacitivity, I and the same set up the android:screenorientation= "landscape." There is no problem here, then added a demand, click on the screen above the "Comments" button, pop-up a dialog box, this dialog I was implemented by activity. The effect is: the vertical screen , the comment interface occupies the middle of the screen, the surrounding is translucent.
The magic happened, the comment window popped up, I found that the back of the playback interface actually turned into a vertical screen. (as said above, this dialog is only a half of the screen, transparent around, so you can see the following interface Playacitivity).
See the screen switch to the vertical screen, I was depressed, I clearly set the android:screenorientation= "Landscape", why also switch it.
Later Google, Baidu ... There's no reason to find out. Self-understanding is this: although playacitivity is obscured, there is still a part to be seen. and the top window (dialog) is set to Android:screenorientation= "Portrait", the screen is only one, must be based on the top of the window set to prevail.
When the screen switches in Android, the life cycle of the activity is reloaded (indicating that the current activity is destroyed, but reloading), how can the current activity not be destroyed when the screen is switched on and off?
Set the Configchanges property for the activity in Androidmanifest.xml.
Configchanges has the following options:
1. Orientation: The screen rotates between the longitudinal and the transverse;
2. Keyboardhidden: Keyboard display or hidden;
3.fontScale: The user changed the preferred font size
4.locale: The user chooses different language setting;
5. Keyboard: Keyboard type changes, such as mobile phone from 12 keyboard switch to full keyboard
6. Touchscreen or navigation: changes in keyboard or navigation mode,
If the Keyboardhidden option is missing, the activity cannot be prevented from being destroyed, and events in the subsequent Onconfigurationchanged event that can only capture a vertical screen to a horizontal screen cannot capture a horizontal screen and a vertical screen.
android:onconfigurationchanged actually corresponds to the onconfigurationchanged () method in the activity. Adding the above code in Androidmanifest.xml means that when you change the screen orientation, eject the software disk, and hide the soft keyboard, you no longer execute the OnCreate () method, but instead execute the onconfigurationchanged () directly. If this code is not stated, the OnCreate () method is executed one time according to the activity lifecycle, and the OnCreate () method usually does some initialization before it is displayed. So if you change the direction of the screen to perform the OnCreate () method, it is possible to create duplicate initialization, reduce the efficiency of the program is inevitable, and more likely because of repeated initialization of data loss. This is a necessity to avoid.
Thank you for reading, I hope to help you, thank you for your support for this site!