Android API Guides Learning--introduction (2)

Source: Internet
Author: User

Application Fundamentals:

Android apps are written in the Java language, and the Android SDK tool compiles code (data files and resource files) in the APK (Android package). APK is a file with a suffix of. apk, 1 apk files contain all the contents of the Android app, APK is the Android-based device used to install the app. Once the APK file is installed, each app runs in its own secure sandbox.

    • Android operating system is a multi-user Linux operating system, each app has a different user.

    • By default, the system assigns a unique Linux user Id,id to the app, and the ID is an unknown to the app. The system sets permissions for all app files, and the app can run only if the user ID is assigned.

    • Each process has its own virtual machine, so the app runtime is isolated from other apps.

    • All apps run in need of their own Linux processes. When the components of some apps need to be executed, they run their own processes. Close a process when the component is no longer needed or when it needs to release memory to his app

In this way, each app implements the principle of least privilege-- by default, each app can only access the fewest permissions it needs to work. This creates a very secure environment: Every application cannot access any part of the system that does not give it permission.

But there are ways to get apps to share data with other apps, or use system resources.

    • It is possible to share the same Linux user ID for two apps, in which case They can access each other's files. To conserve system resources, apps that use the same user ID can run in the same Linux process and share the same virtual machine ( Application must also use the same certificate signature )

    • app can request permission to use device data, such as user contacts, bulk SMS, SD card, camera, Bluetooth, etc. , all app permissions are granted to

    at installation time

The previous content contains a basic knowledge of how apps exist inside the system, and what's left for you to introduce

    • Defining app Core Framework components

    • Declare component and device functionality in the app's manifest file.

    • Resources are independent of application code, allowing your application to gracefully configure the configuration for a variety of devices.

App components:

App components are the basic elements of all apps, each of which is a different point of entry for the system to enter the app, and for the user, not every component is the real entry point for the app, and some components depend on themselves. Each of these components exists in their entity, each with their own unique functions, and play a special role. Each one is a whole that can help determine your application.

There are four different types of components, each of which serves different purposes and has their unique life cycle of how they are created and destroyed.

Activities:

Activity represents a screen of a user interface, for example: An e-mail app might have an activity that shows a list of new e-mails received, another activity to write an e-mail, and an activity to read an e-mail. While all activities in the e-mail app work together to create a powerful user experience, each activity is independent of the rest of the activity. Similarly, one app can launch another app's activity after another app allows it. For example, a camera app can launch an activity in an e-mail app to write emails in order to share photos with other users.

An activity implements a subclass of activity

Services:

A service is a component that runs in the background, can perform long-running operations, or perform actions across processes. A service does not provide a user interface. For example, a service can play music in the background until the user uses a different app, or the service can get the data without blocking user and interface interaction. Another component, such as activity, in order to interoperate with the service, activity can start a service and let him run or bind the service to activity.

A service implements a subclass of the service class.

Content Providers:

Content providers manages a set of shareable app data that you can create on the Web, or in other places where your app can be stored, creating data and SQLite databases from a file system. With content Providers, other apps can query the data and even modify it if content Providers allows it. For example, the Android system provides content provider management connection information. With appropriate permission, an app can query content provider data (for example ContactsContract.Data ) to read or write information about a personal description.

The content providers is useful for reading or writing data. This data is private to your app and cannot be shared.

The content providers implements the ContentProvider的子类。并且为了使app操作事务,必须实现了标准的API集合。 broadcast receivers:

Broadcast receivers is a component that responds to a system-wide broadcast announcement. Some broadcasts are released by the system, such as the screen is off, the battery is low, and the picture is captured. Apps can also publish broadcasts, such as letting other apps know that the data has been downloaded on the device and that other apps can use the valid data. Although broadcast receivers does not display the user interface, they can create a status bar notification that can alert users when a broadcast event occurs. More commonly, broadcast receivers is just a gateway for other components, and broadcast is only going to do a small amount of work. For example, starting a service performs the most basic work of this event.

The broadcast receivers implements the broadcast receiver subclass, and each broadcast provides a intent class.

A special aspect of Android system design is that some apps can launch components from other apps. For example, if you want to capture a photo with your device's camera, there may be another app that implements it, and your app can use it directly instead of developing an activity to capture the photo yourself. You don't need to connect the code from the camera app, you just need to start the activity capture photo in the camera app. When finished, the picture can be returned to the app for your use. For the user, the camera appears to be part of your app.

When the system starts a component, the process of starting a component and instantiating a class is required for this app. For example, if your app launches the activity of capturing photos in the camera app, the activity belonging to the camera app runs in the process rather than running in your app process. Therefore, unlike most other system apps, the Android app does not have a single entry (for example, without the main () method)

Because each application runs on a system separate from other application file permissions, your application cannot activate a component directly from another program, but the Android system can. So in order to activate the component in another Android system, you send a message to the system to designate your intent to launch another app, and then the system activates a component for you.

Translated from the Android website API guide.

Android API Guides Learning--introduction (2)

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.