Activities (activity)
The display layer of the application. Each screen corresponds to your application and will be an extension of the Activity class. Activity uses Views to build the UI to display information and respond to user behaviors. For desktop development, an Activity is equivalent to a Form.
An Activity is usually displayed as a visual user interface. For example, an Activity may be displayed as a list of menu items that a user can select or as the title of some images and images. A message service application may contain an Activity that displays the contact list, an Activity that writes information, and other activities that view information and modify application settings. Although these activities work together to form an application, each Activity is relatively independent. Every Activity is a subclass of Activity (android. app. Activity.
An application may only contain one Activity, or there are multiple activities, just as the messageservice program mentioned above. An application contains several activities and the functions of each Activity depend entirely on the application and its design. Generally, each application contains an Activity that is first presented to the user after the application starts. Enable a new Activity in the Activity currently presented to the user, which can be converted from one Activity to another.
Each Activity has a window for drawing the user interface. Normally, such a window will fill the entire screen. Of course, this window can be smaller than the screen and floating above other windows. Activity can also use some additional windows, such as a pop-up dialog box that requires a user to respond, or a window that shows some important information to the user when the user selects an entry on the screen.
The visible content area of the Activity window is a View with hierarchies similar to the tree in the data structure. The View is represented by a subclass of the Class View. A rectangular area in each view control window. The parent view contains child views and manages the layout of child views. The view on the leaf node directly controls and responds to user actions. Therefore, a view is the interface between the Activity and the user. For example, when a user clicks an image view, it may start an action. Android has many views that developers can use directly, including buttons, text fields, scroll bars, menus, and check boxes.
Call Activity. setContentView () to set the view of the window displaying the Activity. The content view is the root node view in the view hierarchy.
Services)
Invisible "workers" in Android applications ". The Service component is invisible when it is running, but it is responsible for updating the data source and visible Activity, and triggering notifications. They are often used to perform processing that requires continuous operation. When your Activity is no longer active or invisible.
The Service does not have a user interface, but it will always run in the background. For example, the Service may play background music when the user is processing other things, or obtain data from the network, or perform some operations, and provide the Operation structure to the Activity for display to the user. Each Service is extended from the class Serivce.
Playing music on a multimedia player is a good example of the Application Service. The multimedia player program may contain one or more activities through which the user selects and plays music. However, music playback does not require an Activity, because you may want the music to be played continuously, even if you quit the player to execute other programs. To keep the music playing, the multimedia player Activity may start a Service to play music in the background. The Android system keeps the music playback Service running, even after the Activity of the Service is started and exited.
An application can connect to a running Service. After connecting to a Service, you can use the interface exposed by the Service to communicate with the Service. For the Service for playing music mentioned above, this interface may allow users to pause, stop or play music again.
Like activity and other components, Service also runs in the main thread of the application process. Therefore, they cannot block other components or user interfaces. Generally, a thread needs to be derived from these services to execute time-consuming tasks.
Content)
Provides shared data storage. The Content Provider is used to manage and share applications. Content Provider is the preferred method for data sharing between applications. This means that you can configure your own Content Provider to access other applications or the Content Provider exposed by other applications to access their data. The Android device contains several Content providers to access useful databases such as contact information. In Chapter 6th, you will learn how to create and use Content Provider.
Applications can access some private data of other applications through Content Provider, which is a standard data sharing mechanism provided by Android. Shared data can be stored in a file system, SQLite database, or other media. Content Provider extends from the ContentProvider class. By implementing a set of standard interfaces of this class, other applications can access the data controlled by it. However, the application does not directly call the methods in ContentProvider, but uses the ContentResolver class. ContentResolver can communicate with any ContentProvider, which cooperates with ContentProvider to manage communication between processes.
When the Android system receives a request that requires processing by a component, Android ensures that the host process of the component that processes the request is already running. If not, start the process immediately. When the host process of the requested component is already running, it will continue to check whether the requested component can be used. If not, it creates an instance of the requested component to respond to the request.
Intents)
A simple message transmission framework. With Intent, You can broadcast messages throughout the system or send specific activities or services to execute your action Intent. The system will decide which (some) target to execute the appropriate behavior.
Broadcast Receivers (Broadcast receiver)
Consumer of Intent broadcast ". By creating and registering a Broadcast Receiver, an application can listen to Intent Broadcast that meets specific conditions. Broadcast Receiver automatically starts your Android Application to respond to the new Intent. Broadcast Receiver is an ideal means for event drivers.
Broadcase aggreger does not execute any tasks. It is only a type of component that receives and responds to broadcast notifications. Most broadcast notifications are generated by the system, such as changing the time zone and low battery usage. You have chosen an image or changed your language preferences. Applications can also send broadcast notifications, such as notifying other applications that some data has been downloaded to the device.
An application can contain any number of Broadcase Reveiver to respond to notifications that it deems important. All Broadcast receivers are extended from the class BroadcastReceiver.
Broadcast Receiver does not contain any user interfaces. However, they can start an Activity to respond to received information or notify users through icationicationmanager. You can use multiple methods to notify users of new notifications: flashing background lights, vibrating devices, and making sounds. Generally, a program will place a persistent icon on the status bar. You can open this icon and read the notification information.
Notifications)
User notification framework. Notification is used to prompt users without focus or interrupting their current Activity. They are the first choice for Service or Broadcast Receiver to get user attention. For example, when a device receives a text message or an external call, it will notify you by flashing, making a voice, displaying an icon, or displaying a dialog box.