Android app_android Android Development tutorial

Source: Internet
Author: User
Tags comparison table least privilege android sdk manager

First, understand the Android operating system

Android was first founded by Andy Robin (Andy Rubin) and was acquired by Google in 2007, and Google has achieved great success with its Android operating system on smartphones.

1, the characteristics of the Android operating system

The Android operating system is a multi-user Linux system, and each application is an independent user. The system defaults to assigning a unique Linux user ID to each application (this ID can only be used by the system, and this ID is unknown to the application). The system sets permissions on all files for an application, so only the user ID assigned to the application can access them.

Each process has its host's virtual machine (VM), so the code for one application runs independently of other applications.

By default, each application runs in its own Linux process. Android launches this process when any component of an application needs to be invoked. Then, when no components are invoked or the system needs to reclaim memory for other applications, the process is closed.

In this way, the Android system achieves the least privilege principle. That is, each application, by default, can only invoke the work component it needs. This creates a very secure environment in which an application cannot access parts of the system that are not granted permissions.

However, there are many ways to share data with an application and other applications, or to allow an application to invoke system services:

-----It is possible to assign the same Linux user ID to two applications so that they can access each other's files. To conserve system resources,-------applications with the same user ID can be run on the same Linux process and share the VM (must be signed with the same certificate). Applications can access device data by requesting permissions, such as contacts, SMS information, pluggable storage (SD card), camera, Bluetooth 、...... Wait a minute. All application permissions must be granted by the user at the time of installation.

2, the existence of the Android program in the system mode

When you are developing an application running on an Android operating system, the Android SDK tool compiles the code and packs arbitrary data into an Android package, along with related resources, which is actually a compressed file with a. apk suffix. All the code in a. apk file is an Android application.

Installing an application on an Android device installs the. apk file.

Once the installation is successful, the Android program has its own stand-alone sandbox (a sandbox is an approach to running an application in a restricted security environment in order to restrict the code access permissions granted to the application).

Ii. Understanding the Android SDK and API versions

Each version of Android has a unique integer ID called API level. Since users use programs that are always older than the latest releases of the API, the actual Android application must ensure that it works in a multiple-version API environment.

1. Android SDK and project configuration

The Android SDK provides us with an API link library and a collection of development tools for building, testing, and debugging Android applications. Before specifying the Android API version configuration, make sure that you have installed the corresponding version of the Android SDK with the Android SDK manager.

Each Android application must properly configure the API level used, there are three kinds:

Target framework– uses which framework to create the application (compiled).

Minimum Android version– Specifies the minimum version (run) that the Android application can use.

Target Android version– Specifies the version (run) that the Android application is trying to use.

You can also set the three APIs to the same value:

By changing the Target framework to an API version, you can have all of the API features for that version. If you want to be compatible with earlier versions of Android, you can modify the Minimum Android to target option:

The options shown in the above illustration indicate that the Android application developed can be installed on all versions of the Android 4.4.2 to Android 6.0, API 19~api 23. However, although they can be installed on these platforms, there is no guarantee that applications will function properly on these platforms. For example, installing a program on the Android 4.4.2 (API 19) platform, while the code calls a newer version of API than API 19, but does not have a corresponding version of the compiler support, the program will certainly not work on the Android 4.4.2 platform. Therefore, in this case, you must explicitly include run-time checks. For example:

if (Android.OS.Build.Version.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)

{

Builder. Setcategory (Notification.categoryemail);

}

( Note:Android.OS.BuildVersionCodes.Lollipop refers to Android 5.0)

2, the Android API version comparison table

The following table lists the various versions of Android and their corresponding information:

As you can see from the table, the Android version is released very frequently, sometimes several versions a year. How can you make sure that your application is still running reliably in so many versions? This is the role of API level.

3, API level and custom library

When you create an Android libraries project, you should allow developed library functions to be applied to various versions of the API, so you generally do not need to set the minimum level of APIs and the highest levels of APIs, but should follow the following best practices:

When referencing a version of an API, make sure that the API version that the application is running is not less than the referenced version. When you design a custom library function for another Android application, set the minimum API level that you want for the application.

In summary, make sure that the library function you develop uses as few APIs as possible to make the library you are designing more scope-wide.

Debug the application in debug mode

1, debugging the Android application in the simulator

Since the simulator starts slowly, either C # development or Java development, the best way is to start the simulator first, and then Debug.

Typically use VS2015 to debug in debug mode with the emulator. The. apk file generated in debug mode is larger because the default includes debugging information that can be applied to a variety of CPU models in debug mode.

2, debugging the Android application on the real machine

You can also directly debug the application on the real machine, only need to connect the phone via USB to the computer, at this time in the debugging options will automatically appear in the phone model.

Iv. deploying applications to the real machine

After debugging in debug mode, change to release mode, and then publish it to the real machine (the real machine no longer contains debugging information, the resulting. apk file will be much smaller).

Of course, you can further reduce the size of the. apk file by compressing the expansion library. For example, the 3rd Chapter Baidu application debugging environment. apk files are larger, the. apk file size is significantly reduced when the. jar package is separated.

To publish your program to your phone, you need to check the version of the Android operating system on your phone to make sure that the version of the compiler you are writing is consistent with the version of your phone's operating system.

The following is an example of the Android operating system version for 4.4.4, which shows you how to publish your application in C # to the phone to run the specific implementation steps.

Before publishing, change the project properties to API level 19 (corresponding to the 4.4.4 version of the mobile phone), as shown in the following figure:

Then select one of the two methods described below to publish it.

1. The 1th approach

Change "Debug" mode to "release" mode (This step is important, otherwise it cannot be published), and then select "Tools" à "Android" à "Publish android Application" in the main menu, as shown in the following figure:

In the Pop-up Publishing window, select Create New KeyStore, enter Password, click Next, and then enter the alias (alias), Password (Password), the number of years that you wrote (validity years), Information such as your name (A and last name):

Click Next, enter the destination folder for the publication, the application file name, and then click Create, which automatically creates the phonewordapp-aligened.apk file under the target folder.

Note: Make sure that your phone's application settings check "Allow applications from unknown sources."

Copy the published phonewordapp-aligened.apk file to your phone, and then double-click Install and run.

Applications published in this way can also be sold in the Android App store.

2. The 2nd approach

Change "Debug" mode to "release" mode (This step is important, otherwise it cannot be published).

Right-click the project name and choose Export Android Package, as shown in the following illustration:

At this point it automatically generates multiple. apk files in the release folder.

Depending on your phone type, copy the generated matching phonewordapp-signed.apk file (under the project's release folder) to your phone, and then double-click to install and run.

Applications published in this way can only be run directly on the real machine and cannot be sold in the Android App store.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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.