Android weekly learning step by step (7)-activity Introduction

Source: Internet
Author: User

Activity is the most frequent and basic module for Android Developers. In Android programs, activity generally represents a screen on the mobile phone screen. If you compare a mobile phone to a browser, activity is equivalent to a webpage. In the activity, we can add some button elements or check
Box. You can see that the activities can jump to each other. For example, after you press a button, the activity may jump to another activity. A little different from a webpage jump is that the jump between activities may return values, for example, from activity
When a jumps to Activity B
When B finishes running, it may return a value to activity. In many cases, this is quite convenient.

When a new screen is opened, the previous screen is paused and pushed into the history stack. You can return to a previously opened screen through the rollback operation. We can choose a screen that does not need to be retained. Therefore, Android will save the start of each application to the current screen in the stack.

An activity is maintained by the Android system and has its own lifecycle, that is, a cycle of its generation, operation, and destruction ...... Understanding the lifecycle of an activity is very helpful for programming.

--- Android
Development and Practice

1. oncreate ()

Called when an activity is created.

This function is called only once in the acitvity life cycle.

Has a parameter, or is null, or is saved in advance through the onsaveinstancestate () function.

2. onstart ()

Called when the activity is to be displayed to the user.

3. onresume ()

Called when the activity can interact with the user.

This function is optimal if you want to play music or animations.

4. onpause ()

Called when the activity is about to enter the background.

Usually when a new activity is started and displayed, you need to save the program persistent data, such as the data record being edited.

5. onstop ()

This API is called when the activity is invisible and is not required for a period of time.

If the memory is insufficient, the function may never be called and the system will directly stop the process.

6. onrestart ()

Called when the activity is changed from stop to visible again.

7. ondestroy ()

Called before the activity is destroyed.

When the memory is insufficient, the function may never be called and the system will directly stop the process.

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.