(1)-android Study notes: Initial knowledge of Android system architecture and project structure

Source: Internet
Author: User

Android System Architecture

Android Program Structure

Create an Android project that is easy to understand for beginners, switch the program project structure to project mode, and the project structure is as follows

. Gradle and. Idea: These two directories are all automatically generated files from Android Studio, without our concern or need to edit them manually.

app: The code in the project, resources, and so on almost all in this directory, the development work is basically in this directory.

  Libs: If the project refers to a third-party jar package, it needs to be placed in the Libs directory, and the jar packages in this directory will be automatically added to the build directory.

Androidtest: Here is the test case for writing Android test, you can do some automated testing of the project.

Java: This directory prevents all of our Java code from being located, and expanding this directory will see that the myapplicationactivity file for the new project is inside.

Res: This directory contains all the images, layouts, strings, and other resources that the project uses.

drawable start: Put pictures, drawable and mipmap like, just not automatically generated, if in order to compatible with various devices, you need to create a new drawable-hdpi, drawable-xhdpi, drawable-xxhdpi folder, When developing a program, it is best to provide a different resolution version of a picture, placed under these folders, the runtime will automatically select the current device resolution to load which folder picture. If there is only one picture, it is possible to put all the pictures under drawable-xxhdpi.

Layout Start: Placement file

Mipmap Start: Put app icon. (There are many files that start with mipmap, mainly to make the program more compatible with various devices)

Values begins with the configuration of strings, styles, colors, and so on.

Androidmanifest.xml: The entire Android project configuration file, all four components defined in the program are registered in this file, and you can also add permission declarations to the application in the file.

Test : Another way to automate testing of a project by writing a unit test case

. Gitignore: used to exclude the directory or file specified by the app module from version control, similar in function to the outer layer.

build.gradle:gradle Build script for app block, which specifies many projects to build related configurations.

Prohiard-rules.pro: used to specify the obfuscation rules for project code, when the development is finished packaged into an installation package file, if you do not want the code to be cracked, will often confuse the code, so that the crack is difficult to read.

Build: No concern, contains some files that are automatically generated at compile time

gradle: contains gradle wrapper configuration file, using Gradle wrapper in a way that does not need to download gradle in advance, but automatically based on the local cache conditions to determine whether the network download gradle, the compiler does not start by default, If you need to open it, you can click File--settings--build execution,deployment-gradle to make configuration changes.

. Gitignore: This file is used to exclude the established directory or file from version control.

Build.gradle: Project Global Gradle build script, usually the contents of this file do not need to be modified.

. Gradle.properties: A global gradle configuration file, the properties configured here affect all Gradle compilation scripts in the project.

Gradlew and Gradlew.bat: These two files are used in the command line interface to execute Gradle commands, where Gradlew is used in Linux or Mac systems, Gradle.bat is actually used in Windows systems.

local.properties: This file is used to specify the native Android SDK path, which is usually generated automatically and does not need to be modified. Unless the location of the Android SDK in this machine has changed.

myapplication.iml:iml files are all Intellik idea projects will generate a file (Android Studio is based on IntelliJ idea), used to identify this is a IntelliJ Idea Project, there is no need to modify any content of this file.

settings.gradle: This file is used to specify all referenced wood blocks in the project. Because the project has only one app module, this file only references the app module.

Android Project file analysis

Start by running the project you just created.

To open the androidmanifest.xml project configuration file, you can see the following code

        <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name"Android:theme= "@style/apptheme.noactionbar">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>

This XML code indicates that mainactivity is registered for this activity, and no activity that is registered in this file is not available, where the two lines of code in Intent-filter are the most important, <action android:name= " Android.intent.action.MAIN "/> and <category android:name=" Android.intent.category.LAUNCHER "/> Indicates that this activity is the main activity of the project, and the first thing the opener sees is this activity.

Then we look at the Mainactivity.java class in the main-java-, can see inherit from Appcompatactivity, this is a backward-compatible activity, can add the features and functions of each system version to the minimum compatibility to Android2.1 version, Activit Y is an active base class provided by the Android system, and all activities used in the project must inherit from it or its subclasses to have an active attribute. You can then see that there is a OnCreate method, which is the method that must be executed when the activity is created, where there are only two lines of code, and you do not see the Hello word! Typeface, then the run-time explicit Hello word! How did it come about?

The Android program is designed to be logical and view-separated, so it is not recommended to directly write the interface directly in the activity, but rather to write the interface in the layout file and then reference it in the activity. The following code, called Setcontentview (R.layout.activity_main) on the second line of the OnCreate method, indicates that the current activity introduces a r/layout directory Activity_main layout.

protected void onCreate (Bundle savedinstancestate) {        super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_main);

Open the Res/layout directory, you can see the Activity_main.xml file, and then switch to text mode, you can see a <TextView> tag, there is a line android:text= "Hello world!".

(1)-android Study notes: Initial knowledge of Android system architecture and project structure

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.