Android Basic Components-activity

Source: Internet
Author: User

    • What is activity

    1. In the Android program, each Activity inherits from Android.app.Activity,
    2. There is an XML layout file that corresponds to it,
    3. One interface corresponds to an activity,
    4. Each activity needs to be registered in the Androidmanifest.xml
    5. Activity organizes controls by layout management
    • Get control in activity
    1. The controls in each activity will correspond to the R files.
    2. defined in the XML layout file, android:id= "@+id/thisisbutton"
    3. Each control in the layout file has a corresponding class, with the button example, in the layout file for <button/> Its corresponding class as button
    4. Use button button = (button) Findviewbyid (R.id.thisisbutton) reference in activity

    • Jumps between the activity
    1. Use the startactivity (Intent Intent) method to open another activity
    2. Before opening, you can pass parameters by storing variables in the intent.
    3. Create a new activity to jump to
    4. To bind a button to an event

    5. Create a new intent and point to the corresponding activity to complete the page jump

    6. You can populate the intent with data before jumping

      Normal types can be passed between activity, and wrapper classes cannot be passed.

    7. Complete

    • Activity life cycle

Method

Call timing

OnCreate

Called when an activity is created

OnStart

Immediately after the call is created, the activity is about to become visible

Onrestart

Called when it is back to activity, and then calls start after the call is completed.

Onresume

The activity is ready to be called when user action is accepted

OnPause

To switch to another activity call, which is particularly useful for saving some of the current activity's data

OnStop

Called when the current activity is overwritten by another activity

OnDestroy

Called when the activity is destroyed

    • Activity Life Cycle Classification
      • Full life cycle
        • OnCreate () OnDestroy ()
      • Visual life cycle
        • OnStart () OnStop ()
      • Foreground life cycle
        • Onresume () OnPause ()
    • Activity and Task

Accessing multiple activity forms an activity chain in order, called task,android, to manipulate tasks in the form of a stack.

Activity is run according to the rules of the stack.

Android Basic Components-activity

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.