Andriod 的基本原理

应用的基本原理:
Quickview:
Android applications are composed of one or more application components (activities, services, content providers, and broadcast receivers)
Each component performs a different role in the overall application behavior, and each one can be activated individually (even by other applications)
The manifest file must declare all components in the application and should also declare all application requirements, such as the minimum version of Android required and any hardware configurations required
Non-code application resources (images, strings, layout files, etc.) should include alternatives for different device configurations (such as different strings for different languages and different layouts for different screen sizes)

Once installed on a device, each Android application lives in its own security sandbox:
The Android operating system is a multi-user Linux system in which each application is a different user.
By default, the system assigns each application a unique Linux user ID
Each process has its own virtual machine (VM)
By default, every application runs in its own Linux process

However, there are ways for an application to share data with other applications and for an application to access system services:
It's possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other's files.


Activities:An activity represents a single screen with a user interface. An activity is implemented as a subclass of Activity

Services:A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface.A service is implemented as a subclass of Service

Content providers:A content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or even modify the data (if the content provider allows it).A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions.

Broadcast receivers:A broadcast receiver is a component that responds to system-wide broadcast announcements. A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. For more information, see the BroadcastReceiver class.

A unique aspect of the Android system design is that any application can start another application’s component.

When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component. Android applications don't have a single entry point (there's no main() function)

Because the system runs each application in a separate process with file permissions that restrict access to other applications, your application cannot directly activate a component from another application. The Android system, however, can. So, to activate a component in another application, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.

Activating Components:Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent.The other component type, content provider, is not activated by intents.The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver.

There are separate methods for activiting each type of component:
You can start an activity (or give it something new to do) by passing an Intent to startActivity() or startActivityForResult() (when you want the activity to return a result).
You can start a service (or give new instructions to an ongoing service) by passing an Intent to startService(). Or you can bind to the service by passing an Intent to bindService().
You can initiate a broadcast by passing an Intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
You can perform a query to a content provider by calling query() on a ContentResolver.

The Manifest File:
Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. However, broadcast receivers can be either declared in the manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system by calling registerReceiver().
When you declare a component in your application's manifest, you can optionally include intent filters that declare the capabilities of the component so it can respond to intents from other applications. You can declare an intent filter for your component by adding an <intent-filter> element as a child of the component's declaration element.

你可能感兴趣的:(android)