Social Icons

Saturday, May 13, 2017

Structure of an Android application


We saw in the previous chapter how to create a first project on Android Studio. But we did not talk about the files and directories that make up the project. Today we will describe in detail the structure of an android project.

Before running your application, you should be aware of some directories and files in the Android project:

Java

This contains the .java source files for your project. By default, it includes a MainActivity.java source file that has an activity class that runs when your application is launched using the application icon.

res / drawable-hdpi

It is a directory for drawing objects designed for high-density screens.

res / layout

This is a directory for files that define the user interface of your application.

res / values

This is a directory for other XML files that contain a collection of resources, such as string and color definitions.

AndroidManifest.xml

It is the manifest file that describes the fundamental characteristics of the application and defines each of its components.

build.gradle

This is an automatically generated file that contains compileSdkVersion, buildToolsVersion, applicationId, minSdkVersion, targetSdkVersion, versionCode, and versionName.
The following section will give a brief overview of some of the important application files.

The main activity file

The primary activity code is a Java MainActivity.java file. This is the actual application file that is eventually converted to a Dalvik executable and runs your application. Here is the default code generated by the application wizard for Hello World! :
    
    package com.example.helloworld;

    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;

    public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    }
    }

Here, R.layout.activity_main refers to the activity_main.xml file located in the res / layout folder. The onCreate () method is one of many methods imagined when an activity is loaded.

The Manifest file

Regardless of which component you are developing as part of your application, you must declare all its components in a manifest.xml file that resides at the root of the application project directory. This file works as an interface between the Android operating system and your application, so if you do not declare your component in this file, it will not be considered by the operating system. For example, a default manifest file will look like a following file:
   
    
    






  
    
    
  




.
<Application> ... </ application> label components related to the application. Android attribute: the icon will indicate the application icon available under res / drawable-hdpi. The application uses the image named ic_launcher.png located in the drawing foldersThe <activity> tag is used to specify an activity and the attribute android: name specifies the fully qualified class name of the Activity subclass and the: android: tag attributes specify a string to use as the label for the activity 'activity. You can specify multiple activities using the <activity> tags.The action for the intent filter is called android.intent.action.MAIN to indicate that this activity serves as an entry point for the application. The intention-filter category is called android.intent.category.LAUNCHER to indicate that the application can be launched from the launcher icon of the device.The @string refers to the strings.xml file explained below. Therefore, @ string / app_name refers to the string app_name defined in the strings.xml file, which is "HelloWorld". Similarly, other chains are populated in the application.Here is the list of labels you will use in your manifest file to specify different Android application components -<Activity> elements for activities<Service> service items<Receiver> for broadcast receivers<Provider> elements for content providers

The strings.xml file

The strings.xml file is located in the res / values ​​folder and contains all the text that your application uses. For example, the names of buttons, labels, default text, and similar string types enter this file. This file is responsible for their textual content. For example, a default string file will look like this:

The Activity_main.xml file (Layout)

Activity_main.xml is a layout file available in res / layout directory, referenced by your application when building its interface. You will modify this file very frequently to modify the layout of your application. For your "Hello World!" Application, this file will have the following content related to the default layout.
In order to see the message "Hello World!" When running the application, you must add the following code to the main Java file MainActivity.java:



        TextView tv = new TextView (this);
        Tv.setText ("Hello, World!");
        setContentView (tv);

You must also import packages: android.app.Activity and android.widget.TextView;

Here is the final code of the MainActivity.java file:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        TextView tv = new TextView(this);
        tv.setText("Hello, World ! ");
        setContentView(tv);
    }
}

No comments:

Post a Comment

Category Of Mobile Courses

Actualités (644) Adsense (1) Affiliation (1) Algebraic Topology (1) Algorithmic (1) all-news (30) Android (5) Android App (8) Android app without code (4) Android Apps (168) Android Development (4) Android download (2) Android OS (3) AngularJS (1) Automata theory and formal language (5) C programming (5) Category and Functor (8) CMS (3) Computer Glossary (18) Create Mobile App With Ionic Framework (2) CSS (2) CSS-Cascading-Style-Sheets (4) Developpement Java (13) Differential Geometry (1) Django-Python-Framework (8) dropshiping (26) Earn Money by Internet (4) Emplois (23) Framework php (2) Fraud (2) HTML (7) Java For Beginners (10) Javascript (12) Kotlin Programming Language (8) Kotlin For Mobile Android (1) Linux Download (2) Marketing (5) Mobile (3) Mobile Courses (4) Mobile Marketing (4) MoneyGram (1) News (721) Node.js (5) Open Source (1) Photoshop (1) Protect Computer (1) Python (32) Python BeautifulSoup (1) Python For Data Science (2) Python-Books (6) Python-DVD-Training (1) Python-Exercises (138) Python-Framework (1) Python-IDE (1) Python-Modules (1) Python-pdf (2) Python-pyQt (1) Référencement (2) Script PHP (2) Security (6) SEO (1) Snipping Tool: Faq (1) Social Networks (1) Source Code (1) Statistics With SPSS (2) Surveillance Software (1) Travail à domicile (6) Tutoriels php en vidéos (2) Tutoriels-MySql (6) tutoriels-php (19) Utilitaires (1) VPS (1) Web Hosting (1) Webcam (1) Webmarketing (11) Western Union (1) Windows 10 (1) Windows 7 (4) Windows 7 Faq (2) Windows 8 (1) Windows Accessories (1) Windows Download (8) Windows Drivers (1) Windows Fonts (1) Windows Power Shell (2) Windows Registry (2) Windows Security (18) Windows Software (2) Windows Spyware (2) Windows utilities (3) Windows Virus (2) Windows Vista (3) Windows Wireless (1) Windows xp (1) Wordpress (1)
 

Sample text

Sample Text

 
Blogger Templates