How to create android application?

We have already showed how to prepare your machine to develop your android application now it is the time to check if we prepared our machine successfully and we can write our first android application or not.

We will start learning developing android application by writing a simple application that will display "Hello World" sentence (the most famous example to start learning new tech). Follow the next steps to create your first android application:
  1. Lunch Eclipse and select File > New > Project you will find a list of available projects templates select  android project template then click next, you will see window like this 

    Application Name : the name of your applications that will be appear on application list of your device(mobile or tablet)
    Project Name : the name that will be appear in your eclipse work-space.
    Packaeg Name : it will be used as identifier for your application and must be unique across all applications.
    Build SDK : specify which sdk version you will target.
    Minimum required SDK : specify min sdk version required for running your application.
  2. In configure launcher icon window, configure the launcher icon of your application or use the default configuration then click next. 
  3. In Create Activity window check Create Activity chekbox and select BlankActivity and click next.
  4. In New Blank Activity window, specify the activity name, layout name, and title. this window will appear with default values, for now we will use these default values. Click finish button to create your android project.
  5. In Package explorer you will find your HelloAndroid project, expand src folder and open MainActivity.java file replace the code inside MainActivity class with the following code
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      TextView tv = new TextView(this);
      tv.setText("Hello World!");
      setContentView(tv);
    }
    if import android.widget.TextView; statement doesn't exist, add it.
Now we have finished creating our first android application that will display "Hello, world". To run this application we need to create launch configuration and we need also a virtual device on which to run it instead of lunching it on real android device. Follow the following steps :
  1. select Run > Run configuration, in run configuration window double click Android Application in left pane and rename the configuration HelloAndroidConfig, click browse and select HelloAndroid project and leave Launch Default Activity selected.
  2. Click Apply and then Run. Now Eclipse is ready for running your application but you did not create the virtual device yet so it will fire error message "No compatible targets were found. Do you wish to a add new Android Virtual Device?" click yes.
  3. In Android Virtual Device Manager window click new to create one. In Create new Android virtual Device window, name it HelloAndroid2.3.3 and in target field select Android 2.3.3 - API Level 10, in SD Card select size and type 10 (10 MB) and leave the remaining fields with its default values.
  4. Click Create AVD. it will be displayed  in Android Virtual device Manager window. close it by click X in the upper right corner.
  5. Select Run > Run to run your application, eclipse will  start the virtual device (emulator) with your first android application.                                     
Previous steps are the main steps to create any android application, you can take this post as a reference for creating android application, configuring your launch configuration and to create android virtual device(emulator) in the future.

In the next posts we will explore in details what does code we added in this post mean and know more about android framework.

Comments

Popular posts from this blog

ASP.Net MVC : ActionLink with bootstrap icon

ASP.Net MVC : Conditional Validation using ValidationAttribute

Android : How to change progress bar color at runtime programmatically?