My humble opinion on Android's onSaveInstanceState() method

Continue to read Guo Shao's <<the first line of code>>, what should I do when I read that the 2.4.5 event has been recycled? According to the code in the book, I typed it, but when it was executed, there was no execution result! What Guo Shao said in this paragraph is also relatively rough. I can't help it. I google it again, look at other people's articles, and I directly saw an article written by the author for the days when I was on the Internet . , Suddenly, it turns out that the onSaveInstanceState method can only be triggered when an activity is destroyed. Only in the following 5 cases, it is possible to trigger the onSaveInstanceState method:

(1), when the user presses the HOME key. ( Not necessarily )
This is obvious, the system doesn't know how many other programs you want to run after you press HOME, and naturally it doesn't know whether activity A will be destroyed, so the system will call onSaveInstanceState() to give the user the opportunity to save a certain some non-permanent data. The analysis of the following situations follows this principle

(2), long press the HOME button, and choose to run other programs. (Not necessarily)

(3) When pressing the power button (close the screen display). (I don't know which key it is)

(4) When starting a new activity from activity A. (Generally not)

(5) When the screen orientation is switched, for example, when switching from portrait to landscape. (surely)

After testing, only the 5th method is sure to work. I hope it can help students who are as dizzy as me to understand this method!

 

Original address: http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0110/794.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326251649&siteId=291194637
Recommended