"Android4 Advanced Programming Notes" dive into Android Activity

Source: Internet
Author: User

Create activity

To create a new activity, you need to extend the activity class, define the user interface in the new class, and implement the new functionality.

A view is a UI control used to display data and improve user interaction. Android provides multiple layout classes, called ViewGroup, that can contain multiple views to help layout the UI. Fragment is used to encapsulate various parts of the UI, making it easy to create dynamic interfaces.

The activity needs to be registered in the manifest. Add a new activity tag within the application node of manifest; The activity tag contains properties such as tags, icons, required permissions, and metadata such as the subject used by the activity.

In the Activity tab, you can add a intent-filter node to specify the intent that can be used to start the activity.

Lifetime of activity

Android applications cannot control the lifetime of their own processes, while the Android runtime can manage the processes of each application, that is, it can also manage every activity within the process

1.Activity Stack

The state of each activity is determined by where it is located in the activity stack, which is the last-in-first-out collection of all currently running activity.


Status of 2.Activity

Active state: At the top of the stack, the visible, focused foreground activity, when it can receive user input.

Paused state: visible, but not focusable. Unable to accept user input events

Stop state: When not visible. The activity still stays in memory, saving all state information, but when other parts of the system require memory, they become the primary candidates for termination.

Inactive: After an activity is terminated, it is inactive until it is started. Inactive activity has been removed from the activity stack.

State conversions are non-deterministic and are handled entirely by the Android memory manager. Android first shuts down applications that contain inactive activity, and then shuts down those that stop.

3. Monitor status changes

To ensure activity can react to state changes, Android provides a series of event handlers that are triggered when the activity is transformed between the full, visible, and active lifetimes.

4. Understanding the lifetime of activity

Full lifetime: The time range between the first call of the OnCreate method and the last call to the Ondestory method

Visible lifetime: The period between OnStart and OnStop.

Active lifetime: The period between Onresume and the corresponding OnPause

Android Activity Class

The Android SDK contains activity subclasses to encapsulate the use of common user interface widgets. Some of the more useful activity subclasses are listed below.

Mapactivity encapsulates the resource handling that supports mapviewwidget all in one activity

Listactivity activity wrapper class, which binds a ListView to a data source, acts as the main UI element, and provides event handlers for list item selection

Expandablelistactivity is similar to listactivity, but it supports Expandablelistview

"Android4 Advanced Programming Notes" dive into Android 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.