Andriod programming – Posts 9: Structure Project

This much too busy to write a blog that new hours time. Today we will learn the part not related to code too – Android Project structure. This part of the many guides will be introduced shortly the first post, however, according to his friends learn in this class (after studing 8 Beach front) is just beautiful, will not be confused and much easier to acquire.

At this time, his tools are used Android Studio 2.1.2

[qads]

1. Android structured mode

It is true that I have not ever introduced to the structure of 1 Project, let alone tell you this folder is back, what it does, What file is another file,… Because I think that beginners should learn just what you want to have, this is the time for you to learn it. Every school flame has, and then return to the original, and then plunged ^^.
You open up and open Android Studio's Last Project 8 – Intent to offline. Default mode you'll Android.

android-project-struct

We will find out in the order as in the photo numbered offline.

1.1 View Android

This section is only view, you can switch to the Project to see, I will say next slice below the offline mode.

1.2 Module app

By default when you create a new Project will automatically generate this app directory. It is a module, In a project can have a lot of modules, This module can be of different project applications, related to each other or to the library module. At this point you should also know and understand it was enough.

1.3 File AndroidManifest.xml

In each module are 1 as this file, This file is the module's configuration file, what configuration it time you opened it.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nguyenvanquan7826.tut8intent">

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity" />
        <activity android:name=".MainActivity"/>
    </application>

</manifest>

You will see the contents of this file as above, but no 3 current uses-permission…, added to its full structure of the file.

  • The first is package=”com.nguyenvanquan7826.tut8intent”, this is the module package. it also is the id of the application. Each app will bring up the google store must have the package prices vary, no 2 application package can coincide.

  • 3 current uses-permission was 3 his lines added, it can exercise the rights that the application requests from users. When you install any application, often appear first part permisstion asking you agree that the new settings. The readers 3 requirements will recognize as a request for the list of accounts in the phone, retrieve account information, and retrieve contacts.

  • Card application including the entire installation of the application's behavior. Specifically, there are no in-app Activity, of each type of activity, with the service (Underground services run) any applications running in the. Each card will be declared activity for an activity. If Activity or service that does not declare here will not be used. Have you noticed where we have 3 Activity là LoginActivity, RegisterActivity, MainActivity.

  • Declaring an Activity. By default when you create your Activity guides like the day before, it will automatically add the file to declare this AndroidManifest.

<activity
    android:name=".LoginActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

+/ name Activity name, Here you see a dot (.) in front of it is located in the package indicated, ie in com.nguyenvanquan7826.tut8intent, if you create more 1 package with packtemp and put a name Activity Temp will declare is android:name=”.packtemp.Temp” ie it write com.nguyenvanquan7826.tut8intent.packtemp.Temp
+/ label is the title of the Activity, it will be displayed on the top bar.
+/ intent-filter the filter inform the conditions of Activity, here announced it is the main activity android.intent.action.MAIN and is opened first when opening applications android.intent.category.LAUNCHER

1.4 File build.gradle

Have you noticed the other Manifest file is the configuration file management application functions, This file is also the configuration file, but is configured for Android version, configure the library to use in Project.
In the photo above, you look there 2 file build.gradle, but let's just pay attention to the file Module app, open it and will be like this.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.nguyenvanquan7826.tut8intent"
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.android.support:design:24.0.0'
}
  • First line apply plugin: ‘com.android.application’ This module represents an application. Ie it is an application that can run on your phone. If you want to create a module that functions as a library, can be used for many different Project, it is apply plugin: ‘com.android.library’, but here we are only interested whiff app.

  • Next row compileSdkVersion and buildToolsVersion SDK versions respectively and the tool to create applications. This default SDK how much you use, it will automatically get the latest version.

  • Current applicationId “com.nguyenvanquan7826.tut8intent”, it will look in AndroidManifest, is the id of the application.

  • next row minSdkVersion 14 and targetSdkVersion 24 respectively smallest Android Api version can run and run the best version for this Project. When creating Project, it can allow you to choose which. Here api smallest version can run as api 14 Android News 4.0 or more may Vegetarian, What if the machine will use a smaller version can not run this application. Now almost all uphill 4 Should you then to min is api 14 (Android 4.0) or api 16 (Android 4.1).

  • Current versionCode 1 and versionName “1.0” respectively version code and version of the application name. When you update the application code must fix the larger version previous version, the name must be different versions, the new store will be taken up.

  • Smoke dependencies then as the previous post you said it was to add these libraries. For add a library structure, follow the instructions of the person who created it or search his library beam google.

2. Structured in Project mode

You click on Signature Android above to switch to Mode Project.
android-struct-project-1

Have you noticed our content nothing changed outside layout. I will not explain what was done in part 1, just added some new ones.

2.1 Module app

In our project still Module app, it will be bold.

2.2 part output

This section is contained when we debug output file. The APK file debug born here, You can copy the phone on different machines and racing. But note that the debug because they will not give up the store is. I'll have to store the tutorial for own.

2.3 Src directory

This directory contains the source code of java and xml, ie everything about code. In which you pay attention to directory main, This will be a directory in java and folder res. java java files contain, res photo files contained, xml,.. In the folder res, you notice the following points.

  • Folder drawable will contain the image, xml configuration file,… When you create icons from system tools Android Studio will produce various types of drawable folder, corresponding to the type of screen size.

  • Folder layout containing layout I got you.

  • Folder mipmap, only the image file containing the application's icon.