Second, Android learning the next day-the first knowledge of activity

Source: Internet
Author: User
Tags unique id

(Transferred from: http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html)

First, Android learning the next day-the first knowledge of activity

When the program was successfully built yesterday, it was possible to develop and run Android applications because activity is an integral part of development, so be aware of the activity.

The following two points are to be noted: (Personal summary)

    1. In general, the first line in the method body must be super.xxx (), it must first call the corresponding method in the parent class to do the necessary things, and then write the other code according to your own needs.
    2. If you are learning Android from scratch, you do not have to develop the latest version, you can develop it under the lower version (2.3.3), and then compile and run it under a higher version (4.0), which can improve the adaptability of the code and be compatible with the advanced version.

Here is a summary of my study today:

First Android four important part ①activity--image Dot is an app façade that we see on the phone the graphical interface

②intent--It's like a move, to transfer data between activity, like requesting

③service--This is not visible, it is the underlying that provides service support for the entire application

④content provider--interface that provides data to applications

The above description of my own feeling is also more abstract, today specializes in activity, finally keep the cloud open to see the moon Ming:

First, you need to have a general understanding of the Android Project catalog before doing the following:


Self-Summary:

SRC is our own process of writing;

Gen is the system automatically generated when we create the program, do not modify

Assets is a repository that differs from RES in that it does not automatically generate IDs in R.java

Res is a repository, and unlike assets, each additional resource (picture, etc.) will automatically generate the corresponding ID in the R.java

Layout is used to store layouts, which control the display pattern of activity.

A key-value pair stored in a string.xml that can be extracted by activity

Androidmanifest.xml is one of the most important files in the system, storing the activity's registration information, which should be registered here for each activity generated.
The above is the approximate narrative, do not know the clarity of the expression

Activity Learning Notes ~ ~ ~

    • Activity Preliminary Introduction

(summary) activity is a visible container for users to interact with the application and to place multiple controls. I feel that the concept of activity is like a page of our development site, but also a container, but the carrier is different, a computer to see, a mobile phone to see it.

    • Activity considerations, Self-summary

An activity is a Java class and must inherit the activity class.

When an activity first runs, it runs the OnCreate () method, so overwrite this method.

Each activity needs to be configured in a androidmanifest.xml.

To add the necessary controls (some controls) to the activity: Add in the layout file Main.xml, at which point R.java automatically generates a unique ID for the control, which is available through Findviewbyid (R.ID.XXX) in the activity. Make a Call ~ ~ ~ then you can do anything you want to do ~ ~ ~

For people with an object-oriented language base, it's clear that the code doesn't have to be posted.

    • Activity and Intent

The image point, intent is the activity between the bridge, of course, can also be other bridges. Today I only learned two activity passing data through a intent object.

Intent is an object and contains a set of information ①component name--specifies which activity to pass to

②action--specify what the other activity is going to do

Data transmitted by ③data--

④categorty

⑤extras--Key-value pairs are also used to store data for delivery

⑥flags

It is important to note that this activity does not necessarily have to be within the same project.

    • The use of four basic controls

①textview②edittext③button④menu

The specific way to add is very simple, here do not do a demonstration, the program tomorrow ~ ~ ~

It is important to note that the menu addition method differs from the other three:

The other three controls are added in the corresponding layout file, and the Add menu needs to overwrite a method--oncreateoptionmenu (menu menu) in the activity so that a menu is created, but to implement the function, another method needs to be covered- Onoptionitemselected (MenuItem Item) writes the function for each item in this menu.

    • Life cycle of activity

The activity has seven functions related to the life cycle, namely: ①oncreate

②onstart

③onrestart

④onresume

⑤onpause

⑥onstop

⑦ondestory

Here I only make a summary, specifically when to call what online tutorials are more clear than I said

Here I think there are two points to note:

First, when a program starts the last three processes (onpause,onstop,ondestory), it is possible to kill when the system resources are low. Because the phone is not a computer, memory is limited, so the Android system will have its own internal algorithm to save their resources.

Second, ondestory in two cases may be called, 1 is called in the Code of the Finish () method, 2 is when the system resources are insufficient.

There is also a--task necessary to connect with the activity life cycle

A task is a stack of activity, so it has the feature of a stack-LIFO.

What we see on the phone is always the topmost activity on the stack, and it's important to note that the stack in the task has no sort of function.

    • activity--of window Morphology This will be a more extensive activity that we'll use later in the development, similar to a popup, but it doesn't completely obscure the underlying activity.

Using the window form of activity is very simple, just add a property to the Androidmanifest.xml's corresponding activity registration code: ... android:theme= "@Android: style/ Theme.dialog "/>"

What will begin tomorrow is the study of the activity layout. In fact, Android for Java-based people are still relatively easy to get started, refueling

Second, Android learning the next day-the first knowledge of activity (turn)

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.