Cause:
1. Horizontal and vertical screen Rotation
2. After the system is started, find the available mobile network
The oncreate method is triggered. After the application is enabled, the current activity is destroyed in the preceding two cases, and a new activity instance is restarted.
Solution:
1. Add the following settings in androidmanifest. xml.
android:configChanges="mcc|mnc|orientation|keyboardHidden"
2. Reload the following method
@ Override public void onconfigurationchanged (configuration newconfig) {super. onconfigurationchanged (newconfig); // the orientation of the detection screen: vertical or horizontal if (this. getresources (). getconfiguration (). orientation = configuration. orientation_landscape) {// The current screen is a landscape, add additional processing code here} else if (this. getresources (). getconfiguration (). orientation = configuration. orientation_portrait) {// currently the portrait screen, add additional processing code here} // detect the status of the real keyboard: Roll out or close if (newconfig. hardkeyboardhidden = configuration. hardkeyboardhidden_no) {// The physical keyboard is being pushed out, and additional processing code is added here} else if (newconfig. hardkeyboardhidden = configuration. hardkeyboardhidden_yes) {// when the keyboard is closed, add additional processing code here }}
Reference:
Http://www.cnblogs.com/hibraincol/archive/2010/09/18/1829862.html
Http://www.linuxidc.com/Linux/2012-01/50845.htm