Android component concepts

Source: Internet
Author: User

The Android mobile operating system is an open-source system. Friends who have some knowledge about programming can use various programming methods to apply this system to mobile phones to meet various needs. Next we will summarize some concepts of the Android component for your convenience.

  • Android local broadcast Operation Analysis
  • Android Widget Toolkit
  • Basic concepts of the Android Menu System
  • Summary of Android Intent application practices
  • How Android databases work

One core feature of Android is that an application can use the elements of another application (if these applications allow this ). For example, if your program needs to display a scroll image list, another program has an appropriate scroll bar and can be used by other programs, then you can use this scroll bar to complete your work, instead of developing your own. Your application does not need to contain code or connect to other applications. On the contrary, it is only necessary for simple startup.

To enable this feature to work, the system must be able to run a required application of some components and instantiate a Java object for that part. Therefore, unlike applications on most systems, Android applications do not provide a single entry for any part of the application, for example, there is no main () function ). On the contrary, they use system-capable instances and essential components for running. The following are four components:

Activities of Android Components

An activity shows a visual user interface for a behavior with focus and user operations. For example, an activity can display a list of menu options that a user can select or a picture with subtitles. A text message application may have an activity used to display the list of contacts that can send text messages and an activity used to write text messages to the selected contacts, other activities used to view previous text messages and change settings. Although they work together to form a closely linked user interface, each activity is independent from other activities. Each Activity is inherited from a base Activity.

An application can have only one activity, or just a few text messages. What these activities are and how much they are, of course, depends on the application and its design. Typically, one of these activities is marked as the first Activity displayed to the user after the program is started. Transferring from one activity to another only starts the next activity.

Each activity is drawn by a default window. Typically, this window fills the entire screen, but it can be smaller than this window, floating above other windows. An activity can also take advantage of additional windows. For example, a pop-up dialog box waits for the user's response to appear in the middle of the activity, or a window for a single user to display important information when the user selects a special choice on the screen.

The content of this visual window is provided by a set of views and inherited from the instances of the Base Class View. Each View Controls a special rectangular space in the window. The parent class view contains and arranges the layout of child classes. The view at the bottom of the view system is drawn in the rectangle space they control, and the user directly responds to the behavior of the space. Therefore, a view is the place where user behavior interacts. For example, a view may display a small image and create an action when you touch the image. Android has a large number of completed views, including buttons, text boxes, scroll bars, menu items, and check boxes ....

A set of views are filled in the form of the Activity by Activity. setContentView. This content view makes the root view of this system.

Android components Services

Services do not require a Visualized User Interface. On the contrary, services run in the background in an uncertain period. For example, when a user is dealing with other problems, the service can play background music, or he can obtain data, compute, improve, and provide the results required by the activity from the Internet. Each service inherits from the service base class.

A basic example is the songs in the Media Player playlist. Playing an app may have one or more activities that allow users to select songs and play them. However, music playback is not processed by an activity, because the user expects the music to be played after they leave the player interface. To meet this requirement, a service running in the background should be enabled for this playback activity. The system can continue playing the music, even if the user chooses to play the music and leaves the interface.

Can be bound to) a running service can also enable a service that is not currently running ). After the connection, you can use an interface provided by the system to communicate with the service. This excuse allows users to pause, roll back, stop, replay, and play back the music service.

Like activities and other components, services run in the main thread of the application process. Therefore, they do not block other components or user interfaces. services usually generate other threads for those time-consuming tasks, just like playing music ).

Broadcast receivers of Android Components

A broadcast receiver can only receive broadcasts and respond to notifications. Many broadcasts are produced by system code-for example, notifications of time zone changes, insufficient battery, taking a photo, or changing your language preferences. Applications can also send broadcasts-for example, to let other applications know that some data has been downloaded from the Internet, and they can use the data.

An application can have many broadcast receivers to respond to notifications that it deems important. All receivers inherit from the BroadcastReceiver base class.

The broadcast receiver does not display a user interface. However, they can start an activity for the information they receive, or they can use icationicationmanager to notify users. Notifications can be noticed in different forms-flashing background lights, shaking mobile phones, making sounds, and so on. They usually place a temporary icon on the status bar. You can open this icon to obtain information.

Content providers of Android Components

The content provider provides a set of special data that can be used by other applications. The data can be stored in the file system, SQLite database, or other meaningful forms. The content provider inherits from the ContentProvider base class and implements a set of standard methods to allow other users to retrieve and store data. However, applications cannot directly use these methods. They must use the ContentProvider instance to call its method. ContentResolver can communicate with any content provider, and their cooperation can manage inter-process communication.

No matter when a request needs to be processed by a special Android component, Android ensures that the process of this application component is running and starts it if necessary, make sure that the appropriate instance of the component is available and instantiate it if necessary.

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.