Android Core Components activity component

Source: Internet
Author: User

1. Activity profile

One of the four components of the activity component, in the application of an activity can be used to represent an interface, the Chinese meaning can also be understood as "activity", that is, an activity started, on behalf of the activity component start, Activity end, representing the end of an activity's life cycle. An Android app must be run and started through activity, and the lifecycle of the activity is delivered to the system for unified management.

Understanding the following four basic concepts will help us to better understand the internal mechanisms of the Android system:

Activity: The interface in the program

Application: Application

Activity stack: Managing the activity's stack structure

Task: Tasks

2. Activity statusin Android, activity has three basic statuses:(i) resumed: When a new activity is launched into the stack, it is at the very top of the screen at the topmost point of the stack, where it is visible and can be activated with user interaction. (ii) Paused: State when activity is overwritten by another transparent or dialog-style activity. At this point it remains connected to the window manager and the system continues to maintain its internal state, so it is still visible, but it has lost focus and cannot interact with the user. (iii) stoped: When activity is overwritten by another activity, the loss of focus is not visible when it is in stoped state.   3. Activity life cycle

The life cycle approach is detailed:

Official Flowchart:

Code Listing: Life cycle Method Testing (Mainactivity.java)

1  Packagecom.bothsunny.apps.a31_activity;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 6 ImportCom.orhanobut.logger.Logger;7 8  Public classMainactivityextendsappcompatactivity {9 Ten     /** One * This method is called when an activity is created, and we can do the initialization of the component in this method . A      * -      * @paramsavedinstancestate -      */ the @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); +LOGGER.I ("Mainactivity-oncreate"); -     } +  A     /** at * This method is called when activity is visible but cannot be interacted with - * called after OnCreate -      */ - @Override -     protected voidOnStart () { -         Super. OnStart (); inLOGGER.I ("Mainactivity-onstart"); -     } to  +     /** - * Called when activity can interact the * Called after OnStart, after the method is called, the activity enters the active state * * Resumed status $      */Panax Notoginseng @Override -     protected voidOnresume () { the         Super. Onresume (); +LOGGER.I ("Mainactivity-onresume"); A     } the  +     /** - * Called when an activity from the stoped state is reactivated $ * The OnStart () method is then called $      */ - @Override -     protected voidOnrestart () { the         Super. Onrestart (); -LOGGER.I ("Mainactivity-onrestart");Wuyi     } the  -     /** Wu * Current activity is overwritten by another activity, loses focus, but is also visible and cannot be interacted with - * Then the current activity enters the paused state (paused state) About * The Onresume () method is called again when activity is re-acquiring focus in this state $      */ - @Override -     protected voidOnPause () { -         Super. OnPause (); ALOGGER.I ("Mainactivity-onpause"); +     } the  -     /** $ * Current activity is completely covered by another activity, invisible and non-interactive the * Then at this point the current activity enters the stoped state (stop State) the * When activity in this state is re-displayed, the Onrestart () method is called the      */ the @Override -     protected voidOnStop () { in         Super. OnStop (); theLOGGER.I ("Mainactivity-onstop"); the     } About  the     /** the * Called when the current activity is destroyed, indicating the end life cycle the      */ + @Override -     protected voidOnDestroy () { the         Super. OnDestroy ();BayiLOGGER.I ("Mainactivity-ondestroy"); the     } the}
4. Activity Transfer Datain Android, different activity instances may run in a process, or they may run in different processes. So we need a special mechanism to help us deliver messages between the activity. In Android, a intent object is used to represent a message, a intent object not only contains the destination of the message, but can also contain the contents of the message, which is like an email, which should include not only the address of the recipient, but also the specific content. For a intent object, the message "destination" is required, while the content is optional.

Android Core Components activity component

Related Article

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.