Android-activity life cycle

Source: Internet
Author: User

The basic concept of activity, and the life cycle of activity

First, the basic concept of activity

Activity is when you open an app and see an interactive interface that fills the window or hovers over other windows. For activity configuration in Androidmanifest.xml, an application can have multiple activity, and the main activity is configured in Androidmanifest.xml as follows:

 <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <ActivityAndroid:name= "Com.lisa.helloactivity.MainActivity"Android:label= "@string/app_name" >            <Intent-filter>                 <action  android:name= "Android.intent.action.MAIN" />  <category  android:name= "Android.intent.category.LAUNCHER" />                             </Intent-filter>        </Activity>    </Application>

The main activity needs to specify in the <intent-filter> node what the action and category child nodes are displayed on a yellow background, so that the first thing you see when the app starts is this page ... The main activity can jump to other pages by initiating other activity, which is done by using intent in the program to achieve the purpose, typically intent intent = new Intent (), Intent.setclass ( A.this, B.class) to accomplish the purpose of jumping from activity A to activity B.

The switch between the activity is done by pressing the stack (last in, first out), a new activtiy is switched to foreground, the new activity is pressed into the stack, at the top of the stack, the user focus is clicked, and after you click the back key, The activity at the top of the stack is stacked, the last activity reaches the top of the stack, and the user focus is retrieved again.

Ii. life cycle of activity

Let's start with a classic diagram of the life cycle:

Then there are 7 methods associated with Android's life cycle:

1. void OnCreate (Bundle savedinstancestate)

What is bundle savedinstancestate? A bundle is a key-value pair that stores the state of the current activity and is used to facilitate the recovery of state after Onresume or Onrestart.

2. void OnStart ()

3. void Onresume ()

4. void OnPause ()

5. void OnStop ()

6. void Onrestart ()

7. void Ondestory ()

Contains three key loops:

1. Complete life cycle: from onCreate () to ondestory () end

2.Visible life cycle: From OnStart () to onStop ()

3. The foreground life cycle (or the life cycle of the focus): from Onresume () to onPause ()

Android-activity life cycle

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.