After calling Alipay payment in the game (equivalent to switching the application process, so that the original application is transferred back to the background), there is no payment, and it returns directly (equivalent to restarting the original application), and then the game crashes, and no obvious error log is seen. , only see the logs related to the application being recycled, and observe the operation of the life cycle as shown below:
Later, it was found that the application was recycled and restarted due to improper configuration of android:configChanges, which caused the application to crash. The function of android:configChanges configuration is to prevent the application from being recycled and restarted by the system in some cases.
The relevant values of the android:configChanges configuration are as follows:
attribute value |
meaning |
mcc |
The SIM card uniquely identifies the country code in the IMSI (International Mobile Subscriber Identity Code), which consists of three digits. China is: 460. Here, the mcc code has changed. |
mnc
|
The SIM card uniquely identifies the operator code in the IMSI (International Mobile Subscriber Identity Code), which consists of two digits. China Mobile TD system is 00, China Unicom is 01, and China Telecom is 03. This identifier mnc has changed. |
locale |
The local location of the device has changed, generally referring to switching the system language |
touchscreen |
The touchscreen has changed |
keyboard |
The keyboard type has changed, such as the user using an external keyboard |
keyboardHidden |
Accessibility of the keyboard has changed, such as when the user brings up the keyboard |
navigation |
System navigation has changed |
screenLayout |
The screen layout has changed, most likely the user has activated another display device |
fontScale |
The system font scaling has changed, such as when the user selects a new font size |
uiMode |
UI mode changes, such as turning on night mode - new in API8 |
orientation |
The screen orientation has changed, such as rotating the phone screen |
screenSize |
When the screen size information changes (when the minSdkVersion and targetSdkVersion in the compilation options are both lower than 13, it will not cause the Activity to restart) - API13 newly added |
smallestScreenSize |
The physical screen size of the device has changed, which has nothing to do with the screen orientation, such as switching to an external display device - new in API13 |
layoutDirection |
When the layout direction changes, the properties of the layout's layoutDirection cannot be modified under normal circumstances - newly added in API17 |
The value in the above table means that the Activity will be reclaimed by the system under the corresponding circumstances, and restarted when needed. If android:configChanges is configured with one of the above values, it means that the Activity will not be reclaimed by the system under the corresponding circumstances, and then Avoid some unexpected errors (especially some information that needs to be initialized in oncreate. If the Activity restarts, oncreate will not be executed again, resulting in the loss of information initialized in the oncreate method, which will cause the application to report an error, and a null pointer exception will generally occur. )
Question: Why the onCreate(), onNewIntent() or onRestart() method is not executed after the Activity is recycled and restarted, but the onStart() method is directly executed. This is still unknown.
Reference article: http://blog.csdn.net/qq_33544860/article/details/54863895