Today, users report that applications always crash.
Symptom: After mainactivity, any second-level Interface related to the main process will cause the application to crash (Note: It is not caused by a crash, but a crash)
Analysis: 1. Check the log and throw an exception before exiting. However, check the code to find that the exception has been caught and the exception information has been printed.
2. If it is suspected that every activity is implemented and its parent class baseactivity does something bad, a new custom activity does not inherit from its parent class. The activity still exists and exits. (Vinney, thanks)
3. It is found that the custom exitapp () of mainactivity is called every time and the breakpoint is set. It is found that it is initiated by ondestory (), while ondestory () is called by the system.
4. I suspect that the ondestory () of each activity will be called immediately after it disappears from the screen. I wrote a small demo for verification. I started to suspect that it was a machine problem.
5. The Google Keyword "Samsung activity flashback" has come out. I posted a smiling post at http://zhidao.baidu.com/question/493015963.html. Locate the cause.
Cause: the Samsung device has a "Developer option → do not retain activity (delete every activity immediately after the user leaves)", which will call mainactivity after entering and leaving from mainactivity. ondestory (), causing the exit Operation to crash (edit by sodino)
Resume: cancel the "do not retain activity" option.
Is there a solution that can be solved in the app even if "do not retain activity" is selected? Yes. ondestory () at mainactivity does not call the exit operation. May overwrite finish (). When the Code explicitly calls finish (), it will exit the application. However, there is still a disadvantage: When activity. ondestory () is returned from the second-level interface by pressing the return key to mainactivity, there will be a short black screen, and then it will be restored.