First, how did the problem arise?
Evening review code, found that an activity did not call their own OnDestroy method I am very puzzled, so I checked the code. After the discovery of the finish code followed by the following code finish (); System.exit (0);//This is the culprit.
Why is this writing going to be a problem?
System.exit (0);////look at the prototype of the function public static void exit (int code)//added in API level 1//The main idea can be interpreted as, call this method, will stop JAVAVM execution, Equivalent to killing the program causes the VM to stop running and the programs to exit with the given exit status. If Runfinalizersonexit (Boolean) have been previously invoked with a true argument and then all objects would be properly garbag E-collected and finalized first. Since we understand that after the call to exit, the program will be killed, the whole program has been accidentally (artificially) killed, this is not normal situation, therefore, the Activiy life cycle will not continue to execute. A good explanation of why OnDestroy will not execute the question.
So, how is the problem solved?
Will System.exit (0); This code is removed from finish (), resulting in the program life cycle, performed normally. Problem solved. Note: I think this sentence is not necessary to write, as an Android developer, should use finish to control the interface of the app reasonably, and the life cycle to the system to process, so as to write a robust program code.
[Android Fundamentals] Why did the system not call the OnDestroy method after the activity exited?