Life cycle and usage scenarios for activity in Android

Source: Internet
Author: User

#1完整生命周期代码如下.
Package Com.wzw.lifecycle;import Android.app.activity;import Android.content.intent;import android.os.Bundle; Import Android.view.view;public class Mainactivity extends the method called when the Activity {//was created @Overrideprotected void OnCreate ( Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); System.out.println ("OnCreate");} The method that is called when it is destroyed @overrideprotected void OnDestroy () {System.out.println ("ondestory"); Super.ondestroy ();} The method called when the activity interface user is visible @overrideprotected void OnStart () {System.out.println ("OnStart"); Super.onstart ();} @Overrideprotected void Onrestart () {System.out.println ("Onrestart"); Super.onrestart ();} The method called when the activity interface user is not visible @overrideprotected void OnStop () {System.out.println ("onStop"); Super.onstop ();} The interface begins to get the method that corresponds to the focus. (The interface button can be clicked, the text box can be entered content) @Overrideprotected void Onresume () {System.out.println ("Onresume"); Super.onresume ();} The interface loses focus corresponding to the method (pause) (the button is not clickable, the text box is not input content, but the user can still see the interface) @Overrideprotected void OnPause () {System.out.println ("OnPause"); SupEr.onpause ();} public void Click (View view) {Intent Intent = new Intent (this,secondactivity.class); startactivity (Intent);}}


#2生命周期

Full life cycle oncreate--"onstart--" onresume--"onpause--" onstop--"Ondestory"


Visual life cycle onstart--"onresume--" onpause--"OnStop


Foreground life cycle onresume--"OnPause interface user is still visible, but loses focus

#3使用场景1. Application exits auto-save data ondestory OnCreate
2. Application minimized paused operation OnStop OnStart video player
3. Pause the game and start the foreground life cycle
#4TipsCalled OnCreate () when it is created----destroy call Ondestory ()
The method that is called when the activity interface user is visible onstart ()----The method that is called when the user of the activity interface is not visible onStop ()

The

interface begins to get the method that corresponds to the focus. (The interface button can be clicked, the text box can be entered content) Onresume ()----interface loses focus corresponding method (pause) (button cannot be clicked, text box is not input content, but interface user can still see OnPause ()

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.