[Android General] Rachid.Ala:
New Android project​

Finally! We reach the goal! Now it's good, our environment is in place. If you have not had any problems so far, you are ready to create a new Android project.

Create a new project

To begin, select from the menu "File" -> "New" -> "Project". With the ADT plugin, you now have the option to create a "Android Application Project". Select this option and click "Next". Then you come to the window, which allows you to initialize your Android project:

Here are the important information to fill :

Application name: This time it is the name of your application. That will appear in the very eyes of the user. You can put special characters if you wish.

Project Name : This is the name that will define your Eclipse project. You can put whatever you want but avoid spaces and other special characters.

Package name: By convention, the name of a package is in the form of a "url upside down ." You can put your personal domain name or whatever you want. As long as you do not post your application on a large scale , it is not very important.

Minimum required SDK: This is the minimum number required API to run your application. You can not install the application on a mobile with an older API.

Build Target : Select the version of Android on which you want to work .

Click "Finish" to create your project.

Application code

Code créé par défaut

Here is the code created by default:

package com.test.helloxda_university;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

This code contains various elements:

Package Name

some "import" android.*** : Required libraries to the script

The class MainActivity that inherits from Activity.

I will not detail what constitutes the onCreate() method because we will now change it.

Code of our "Hello XDA-University!"

The purpose of our application is to say "Hello XDA-university". For this, we need a field "text". On Android, a field of this type is a TextView (Android, all the elements are based on the View class).

We create our TextView with the following line:

TextView tv = new TextView(this);

This requires to import the corresponding library:

import android.widget.TextView;

we apply a text to our TextView:

tv.setText("Hello XDA-university !");

Finally, we apply the TextView to the current view:

setContentView(tv);

You will notice the following line:

super.onCreate(savedInstanceState);

It can tell Android how to start the application (we call the onCreate method of the parent class by passing the savedInstanceState, which is the previous state of the application).

Complete code (what a code!) of our application:

package com.test.helloxda_university;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

TextView tv = new TextView(this);
tv.setText("Hello XDA-university !");

setContentView(tv);
}
}

With this, our text should be able to be displayed without issues. :)

Launch the application in the AVD

To launch the application, choose "Run" from the menu ... "Run"

The AVD will then take a few moments to start: you will see the letters "ANDROID" in gray on black background. This might take some time depending on your configuration.

Once the AVD is fully started, your application will launch automatically:

Ta daaaa! :cowboy:

Well I told you: nothing transcendent ... But we must start somewhere. ;)

We arrive at the end of this tutorial dedicated to the establishment of an environment of Android development. This is not the only way.

There are many steps to finally not much except a little "Hello!" ... But you are now armed to get started with Android. I leave it to you to learn the art of developing Android applications: Sights, Activities, Intents, etc. .... ;)

I hope you learned something with me and if you have any questions do not hesitate to ask me.