Android noun Description

Translated from: OReilly - Learning Android

Activity

activity generally refers to the content at the same time, the user sees on the screen of a single device. Application comprising a plurality of activity, all of the operations the user is constantly between these switching activity.

It is similar to multiple pages of your site. Contrast Android application, a Web site that contains a home page, and android application contains a main "activity", it is what we usually open the first application screen is displayed. And as providing multiple pages on the same page of the site navigation menu, andoird application should also include this feature.

Activity Lifecycle

Open state
when there is no activity and a memory, which is open. When the activity is being turned on, it is going to be instantiated through a series of callback method. Then, this activity will go into operation.
Note: During the program run, the transition from the open state to the operating state is the most resource-consuming operation, and will directly affect battery life. This is why the system does not automatically destroy the activity is no longer displayed. Users may want to return to the activity, so we'll save them some time in memory.

Run state
Run state means that activity is currently running on the screen, and a direct impact on the user. It can be said that this activity is active, all user interaction, such as input, touch screen and click the button will be dealing with this activity. So, at the same time only a running activity.
A running activity has permission to priority access to memory and resources. Because Android needs to be in a state of operational activity in the active state, and timely response to the user.

Paused state
when the activity is in the inactive state (that is, without affecting user behavior), but still with the screen, which we call paused state. This is not a typical design, because the screen of the device is usually small, and one activity or occupy the entire screen, or do not occupy little space. We often encounter this situation, a dialog box pops up in front of a activity, triggering activity suspended. All activity into a stopped state by the paused state.
But because they are visible, and the screen can not be removed, it can always be priority access memory and other resources.

Stopped state
when an activity is in the invisible state, but still running in memory, we call the stopped state. Stopped activity may be transferred back to again become a running activity. Alternatively, it may be destroyed and removed from memory.
The system will keep the activity held in the stopped state, because the user may at any time to go back to the activity, and restart a stopped activity is far less than the cost to open a activity from scratch. That is because the system has loaded all objects into memory, then the user can very easily be transferred to the foreground.
Stopped the activity can be removed at any time memory.

Have destroyed the state of
an already destroyed activity is not present in memory. The activity manager to decide whether this activity is no longer needed and can be removed. Before activity is removed, it may have to perform some operations, such as saving unsaved information. However, before activity is destroyed, it can not guarantee will first be stopped. A paused activity can also be destroyed. Thus, for example, do the important work of these save unsaved data in a paused state, better than doing time has come to destroy the state.

Note: The fact that an activity is running does not mean it did a lot of things. It may just be in a listening state, waiting for user input. Similarly, in a stopped state activity not have to do nothing. Named state usually refers to whether this activity actively waiting for user input, in other words, the state mainly refers to an activity is visible, it is in an active state.

Intent message body
for the activity between different instruction transfer call, explicit and implicit divided into two ways, by indicating explicitly for the component to be called, is implicitly declared type, and the user needs to call the system to determine the s component. For example, open the browser, we are designated to open the Maxthon browser, or just declare open the browser, allows the system to help us choose.

 

Services Service

Run in the background without any interface elements, similar to the function and activity, but do not care whether displayed on the screen. For example, when we look at e-books in the background of the background music.

Note: different from the linux services, android's services is to call itself a linux services, serves and deamons generated function.

services life cycle is simple, just start, run and destroyed. Therefore, as a developer, you should be concerned about the services we have created yourself, do not let it waste too many system resources, such as CPU, power and so on.

Note: The service runs in the background does not mean that it runs in a separate thread. However, if a service is currently executing task requires more time to complete, then we should be allowed to run in a separate thread. And doing so will cause the user's current thread running relatively slow. Further, activity Services and applications running in the same main thread, which is commonly referred to as the UI thread.

 

Content Providers Content Provider

Content Providers to share data between applications interface. Typically, in order to give application data separate from other applications, android so that each application runs in its own sandbox in the first independent. Small packets passed between applications through intent, and Content Providers deliver better suited greater, lasting words packets. Content Providers API for good support CRUD, so that applications can share data through it. E.g. Contacts Provider (contact provider) as a Content Providers, all contact data for each user application. Settings Provider (setting information providers) to provide all the system configuration information for the application, and the application of its own set of information. Media Store (media store) provides storage and sharing of multimedia data, such as photos, music and so on.

 

BroadCast Receives broadcast receiver

BroadCast Receives a system-level publish / subscribe mechanism. Precisely, it is to achieve observer pattern. The recipient has subscribed to some static code when an event occurs, they will immediately be activated.

The system itself has been broadcast event. For example, an SMS message is delivered, a call comes in, the battery power is low, or boot, etc., all these events will be broadcast system, and many recipients will be triggered to activate.

 

Application Context Application Content

All activities, services, content providers, and broadcast receivers combined make up an application. They run in the same Application Context in. Application Context provides a runtime environment for applications, and run a process on which the respective component. It allows sharing of data and application resources between various components.

In applying the first component to open, Application Context is created, the application continues to be destroyed. We can get a quote by Context.getApplicationContext () or Activity.getApplication ().

Note: Activities and Services is a subclass of Context.

 

Reproduced in: https: //www.cnblogs.com/lullabyus/archive/2012/01/16/2323919.html

Guess you like

Origin blog.csdn.net/weixin_34209406/article/details/93771290