Small white Android Note "1"--android one of the four components (Activity)

Source: Internet
Author: User

I. What IS activity

Activity is an application component and is one of the four components. Provides an interface for users to interact with the program.

Second: How to create activity

1. The activity class that inherits Android

2. Rewrite method OnCreate ();

3. Setting the Display layout

4. Register at Activityminifast.xml

5. By default, when we create a new Android project, a mainactivity is created automatically:



6. Next, a mainactivity is registered by default in Androidmanifest.xml:


Three. Life cycle of activity

OnCreate ();--------Create, OnStart (),----------Run, onresume ()------Get focus, onPause ()-------lose Focus, onStop ()----------Pause, OnDestroy ();-----destruction, Onrestart ();-----restart

Four. Four states of activity

--Active state (active/running) activity at the top of the interface, getting focus

--Paused state (Paused) activity loses focus but is visible to the user

--Stop State (Stopped) activity is completely obscured, but retains the status and member information

--Non-operational status (killed) activity was destroyed.

Five. Multiple activity is jump through intent.

The following example is passed by clicking the button intent. Implement a jump.

Create a firstactivity and secondactivity respectively, and register the activity information in the Androidminifest.xml.


Create a factivity_main.xml and Sactivity_main.xml layout file, respectively.



The first button is a intent example that implements a parameterless return.



The second button is clicked to go to the second page and returns to carry the parameters back over. As shown in the following code



At the same time, Secondactivity.class also need to handle the button.


Run the following:




Small white Android Note "1"--android one of the four components (Activity)

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.