<span id="Label3"></p><p style="text-align:center;"><p style="text-align:center;">Objective</p></p><p><p>Mastering the Activ life cycle is important for any Android developer, and when you understand it well, you can write more fluid and consistent programs/applications. Your program will have a better user experience.<br></p></p><p style="text-align:left;"><p style="text-align:left;">(i) activity status: Each activity may have a maximum of four states in its life cycle<br style="text-align:left;"></p></p><p style="text-align:left;"><p style="text-align:left;">A: Running state, when an activity is located at the top of the fallback stack, This is the activity is in the running State. The system does not recycle activities that are in the running state, which can result in a very poor user experience.<br style="text-align:left;"></p></p><p style="text-align:left;"><p style="text-align:left;">B: Pause state, When an activity is not at the top of the stack, but still visible, then it enters a paused state. What is called not the top of the stack but also visible, such as pop-up box activity, at this time does not occupy the entire screen, the following layer of activity is visible. The inactive activity is still fully alive, and the system will only consider recovering the activity if the memory is very low. Of course you can also call the finish () method to force the Collection.<br style="text-align:left;"></p></p><p style="text-align:left;"><p style="text-align:left;">C: Stop state, When an activity is not at the top of the stack and is completely invisible when it enters the stop State. however, the system still preserves the state and member variables of the response for such activity, and when memory is needed elsewhere, the inactive activity is likely to be reclaimed by the System.<br style="text-align:left;"></p></p><p style="text-align:left;"><p style="text-align:left;">D: Destroy state, When an activity is removed from the fallback stack, it is programmed to destroy the State. The system recycles activities in this State to ensure that the phone has sufficient memory.<br style="text-align:left;"></p></p><p><p><br style="text-align:left;"></p></p><p style="text-align:left;"><p style="text-align:left;">Two Life cycle of Activity:</p></p><p style="text-align:left;"><p style="text-align:left;">Let's take a look at the official Standard chart</p></p><p style="text-align:center;"><p style="text-align:center;">650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M01/79/D8/wKioL1acqfWCB9OfAAKKucqDlcc734.jpg "title=" Activity.jpg "alt=" wkiol1acqfwcb9ofaakkucqdlcc734.jpg "/></p></p><p style="text-align:left;"><p style="text-align:left;">See here must have a little context of the pro, Small series to introduce the next Simple.</p></p><p><p>A:oncreate (); This method must have been seen hundreds of times, at the time of project creation there will be a main class inherited to the activity, and all rewrite this method, he will be the first time the activity was created when the Call. You should do some initialization in the method, such as loading layouts, binding events, generating some necessary parameter data, and so On.<br style="text-align:left;"></p></p><p><p>B:onstart () Method This method is called when the activity is visible from the invisible, generally without our rewriting.</p></p><p><p>C:onresume (); This method is called when the activity is ready to interact with the User. At this point the activity must be at the top of the fallback stack and in a running State.<br></p></p><p><p>D:onpause (); This method is called when the system is ready to start or resume another Activity. We should dispose of some cpu-consuming resources in this method, and save some related data, This method must be executed quickly, otherwise it will affect the use of the new stack top Activity.<br></p></p><p><p>E:onstop (); This method is called when the activity is completely invisible, and the difference between his and OnPause () methods is mainly in: if the new activity started is a dialog-box activity, then OnPause (); the method is executed, and OnStop () Method is not Called.<br></p></p><p><p>F:ondestroy (); This method is called before the activity is destroyed, and then the state becomes Destroyed.<br></p></p><p><p>G:onrestart (); This method is called before the activity stop state transitions to the running state, which is equivalent to Rebooting.<br></p></p><p><p>The above method except the Onrestart () method, the other is the quantity Relative. The activity can then be divided into three lifetimes.</p></p><p><p>①: the complete lifetime, which is experienced between the activity in the OnCreate () method and the OnDestroy () method. In general, an activity completes various initialization operations in the OnCreate () method, while the OnDestroy () method completes the operation of freeing Memory.<br></p></p><p><p>②: visible lifetime, that is, activity in the OnStart (), method and OnStop (), method between the Experience. This phase may not be able to interact with the user, but the total activity is Visible. We should reasonably manage those resources that are visible to the user through these two methods, such as loading the resources in the OnStart () method, and freeing the resources in the OnStop () method to ensure that the inactive activity does not consume too much memory on the System.<br></p></p><p><p>③: foreground lifetime, level activity is experienced between the Onresume () method and the OnPause () method. When the total activity in this lifetime is running, the activity at this time can interact with the user, and the most we see is the activity of that lifetime .....<br></p></p><p><p>This article is from the "easy to follow the cultivation of the road" blog, please be sure to keep this source http://konglong.blog.51cto.com/9153276/1736261</p></p><p><p>Android activity status and life cycle summary</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service