Android Development, inevitably embedded in the application of some advertising SDK, after embedding a number of SDKs, found that almost every request in the Androidmanifest.xml declaration activity of the Advertising SDK will be asked to add this sentence attribute:
Android:configchanges= "Orientation|keyboard|keyboardhidden" by checking the Android API to learn Android:o Nconfigurationchanged actually corresponds to the onconfigurationchanged () method in the activity. The implication of adding an appeal code in Androidmanifest.xml is that when you change the orientation of the screen, eject the software tray, and hide the soft keyboard, the OnCreate () method is not executed, but the onconfigurationchanged () is executed directly. If this code is not declared, the OnCreate () method is executed once according to the activity's life cycle, and the OnCreate () method usually does some initialization before the display. So if you change the orientation of the screen to execute 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 requirement that must be avoided.
To understand the problem, a demo was written to observe the results of the execution.
1 public class Consoleactivity extends Activity {2 private String str = "0"; 3 4 protected void OnCreate (Bundle savedinstancestate) {5 super.oncreate (savedinstancestate); 6 & nbsp //Analog data Initialization 7 str = "1"; 8 LOG.E ("FHT", "onCreate:" + str); 9 }10 @Override14 protected void OnStart () { Super.onstart (), + //analog display, data changes ( &NBS) P str = (new Date ()). GetTime () + ""; LOG.E ("FHT", "OnStart:" + str), }20 21 22 @Override24 public void onconfigurationchanged (Configuration newconfig) {+ super.onconfigurationchanged (newconfig), LOG.E ("FHT", " Onconfigurationchanged: "+ str); }28}
As you can see, when the screen orientation has been flipped three times, three flips did not re-enter the OnCreate () method, so the value of STR is continued, If you remove the relevant code for onconfigurationchanged in Androidmanifest.xml, the execution order of the program will change, each time the screen orientation changes will cause the STR value reset. This is what most of the development process does not want to see.
It is also important to note that the Onconfigurationchanged () method: Super.onconfigurationchanged (Newconfig), must not be omitted, Otherwise, a: Android.app.SuperNotCalledException exception is thrown.