The first activity of the four components of the Android melted down series

Source: Internet
Author: User

There was no serious study of Android for a while, Android is my first technology to enter the circle of software development, Android has become a mantra and so on. When learning Android Most of the time is quickie floating on the surface, a lot of knowledge points without deep learning, Cause the foundation is not very solid now. In the face of some high technical problems, the idea is easy to break, so I decided to use a blog to record the process of melted down learning. Online blog is a lot of, and I want to write some of their own things, is the words more verbose but easy to understand things, There will not be a lot of code that the Novice can not understand, the code that appears each line I will comment what meaning. I've always been a beginner. "The True master is always in the heart of an apprentice," said the sword-saint. Haha, though I'm not a master yet.

The first is the activitty,android of the four major components. It is almost the most important component. Start melted down today with the activity.

I. What is activity?

The four components of Android are Activty/service/broadcast receiver/content Provider, respectively. Activity translation is the meaning of activities, in the Android can be understood as a user can see a page and can interact with the user. You can say that all you can see in an app is activity. We can put a lot of things in one activity, such as lists, pictures, buttons and so on. And then through other components to make these "dead" things into "live". How to turn them into live, will be updated in the subsequent blog.

The life cycle of the 1.1 activity

To learn activity you have to mention his life cycle, and it's vital! Every break in the life cycle plays a unique and irreplaceable role in the activity's life, just as there are many crucial periods in our lives.

To understand the life cycle, you must have a deep understanding of the operational state of the activity, with an activity roughly four running.

A. Operational status: The activity is in the foreground, which you can see and get the focus. (Getting the focus is the ability to manipulate the meaning of interaction)

B. Paused status: Activity is still in the foreground, still visible, but loses focus. For example, if you are playing, you will see a text message, the Text message dialog box does not occupy the entire screen but a small piece, at this time you can both manipulate the reply message, You can see some of the pages but can't manipulate the page. This is called the current activity is paused.

C. Stop state: Activity is not visible and loses focus. For example, you exit from a person's dialog page to see a friend circle, and then say that the dialog page activity is in the stopped state. You can't see him.

D. Destruction status: Activty is completely over, like a person's life is over.

When you understand the running state of an activity, you should understand how his specific life cycle works. Behind every running state are hidden life cycles. Haha ~

The activity has a total of seven declaration cycles: Oncreat () Onstrat () Onresume () OnPause () OnStop () ondestory () Onrestart (). You should have a general idea of what they mean by reading English.

Oncreat is the first method of life cycle, meaning to create! That is, it is called when an activity is created. In this method, you can do some initialization operations, such as loading the layout, initialization method, etc.

@Override protected void onCreate (Bundle savedinstancestate) {

Super.oncreate (savedinstancestate);

Setcontentview (r.layout.activity_main); }

OnStart is the method that is called when Activty is created and then displayed to the screen, which means that you can see the activity but not yet interact

@Override protected void OnStart () {

Super.onstart (); }

When Onresume is called back, it can interact with the activity, like when you click on a button, a picture or something.

@Override protected void Onresume () {

Super.onresume (); }

The OnPause method is to pause this method is called when the above mentioned pause state, such as you are texting suddenly a phone call this method to save the text you are texting, you can write some methods to save what you are typing, or wait until your phone hangs All the text you've been texting is gone, well, this user experience doesn't want to have it? That's the way it works!

@Override protected void OnPause () {

Super.onpause (); }


The OnStop method is to pause immediately after the OnPause call an activity to stop, first to pause

@Override protected void OnStop () {

Super.onstop (); }

Ondestory is destroyed immediately after the OnStop, and the same activity must be stopped before it can be destroyed.

@Override protected void OnDestroy () {

Super.ondestroy (); }

The Onrestart method restarts when an activity is destroyed and the system re-opens the activity to call this method

@Override protected void Onrestart () {

Super.onrestart (); }

The first activity of the four components of the Android melted down series

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.