Saturday, September 7, 2013

Hello World app

After installing necessary tools for Android development, this post provides you step by step guide to create your first app for Android mobile devices.

1. Go to the folder where you put your Android SDK. In the eclipse directory, double-click the eclipse.exe file to launch the eclipse program.

app workspace

2. When the Workspace Laucher opens, enter or select a directory that will be the workspace for your app. Then wait one or two seconds for eclipse to prepare the workspace for you.
3. To create your new app, select the File->New->Android Application Project to open the  New Android Application window. In the Application Name textbox, enter your app name. For this first app, just enter Helloworld for this textbox.

new app creation

Then click Next until you see the Finish button. Click the Finish button to complete the app creation task. The below screen displays after you click the Finish button.

app is created

Run Helloworld app

To run the Helloworld app, firstly you will need to create a emulator. Your app will run on this emulator. The steps below help you to create an emulator to run your app.
1. On the Window menu, select Android Visual Device Manager. On the Android Visual Device Manger window, click New... to create a new emulator.
2. In the AVD Name textbox, enter the name of the emulator. For the Device drop down list select a device for the emulator. See the picture below.

creating emulator

3. After filling the form, click OK to create the emulator.

Now you have a simulator setup. To run the Helloworld app, select Run->Run Configuration... to open the Run Configuration window. On this window, double-click Android Application. In the Project textbox, type Helloworld and under Launch Option, select Launch. From the Launch drop down list select com.example.helloworld.MainActivity. Then click Run to run the app. You will wait until the emulator displays the result as shown in the picture below. This generally takes two to fives minutes for the first run. When the result is shown, don't close the emulator. For the next run, it will be faster.

run app

When the app created, some directories and files are created in your app workspace directory. These directories and files are anatomy of the Android app. The important directories and files are shown below:
1. bin directory contains the binary .class files and .apk file of your app (helloworld.apk). This apk file can be installed on the mobile devices.
2. gen directory contains .R file that references all resources found in your app.
3. res/drawable directory contain drawable resources such as images, shapes defined in xml file format for extra high, high, medium, and low screen resolution.
4. res/layout directory contains xml files that are used as layouts of your app interfaces.
5. res/menu directory contains a xml file that defines menu and its items in your app.
6. res/values contains xml files that define the default screen margins, string values, and styles to be used in your app.
7. src and its sub-directories contains the java source files of your app.
8. AndroidManifest.xml file defines the characteristics of your app such as app version, minimum and target SDK versions, activities, etc. file

The file is the starting point of your app. In this file, MainActivity class extends the Activity class.
package com.example.helloworld;
import android.os.Bundle;
import android.view.Menu;

public class MainActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;

The Activity class has the following methods that you should know:

1. onCreate method is invoked to create interface for the main activity. The activity_main.xml file is the source for the app interface. Components that will be parts of the interface are define here. You can find the activity_main.xml file in res/layout directory.

activity_main.xml file
<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >

        android:text="@string/hello_world" />


2. onStart method is immediately invoked after the onCreate method to start the activity. However, the user still can't interact with the app interface.
3. onResume method is invoked after the onStart method to bring the interface to the front so that the user can interact with the app interface.
4. onPause method works when an activity is obscured by another activity. When the activity in the pause state, it does not receive input or execute any code.
5. onStop method is invoked when the user leaves the activity. This method always called after the onPause method is called. When the activity is in stop state, app interface is invisible and the focus is on a separate activity.
5. onRestart method is invoked when the user returns to the previously stopped activity. The methods that are invoked immediately after the onRestart methods are onStart, and onResume.
6. onDestroy method is invoked when the system dispatches a final signal of clearing the app from the memory. In this method, you should close the connection to the database, or long-run processes that can leak your memory.

strings.xml file

In the strings.xml file (in res/values directory) string resources are defined. A string entry has two parts--name and value. For example, the first string entry name is app_name and its values is Helloworld.

<?xml version="1.0" encoding="utf-8"?>


    <string name="app_name">Helloworld</string>
    <string name="action_settings">Settings</string>
    <string name="hello_world">Hello world!</string>


The strings defined in the strings.xml file can be used in other layouts xml files.
For example, the string hello_world is used as the text of the TextView component in the activity_main.xml file: android:text="@string/hello_world".


  1. Lớp học kế toán tổng hợp thực hành tại hải phòng
    Lớp học kế toán tổng hợp thực hành tại biên hòa đồng nai
    Lớp học kế toán tổng hợp thực hành tại vinh nghệ an
    Lớp học kế toán tổng hợp thực hành tại hải dương
    Lớp học kế toán tổng hợp thực hành tại ninh bình
    Lớp học kế toán tổng hợp thực hành tại hưng yên
    Lớp học kế toán tổng hợp thực hành tại phú thọ
    Lớp học kế toán tổng hợp thực hành tại hà nam
    Lớp học kế toán tổng hợp thực hành tại vĩnh phúc
    Lớp học kế toán tổng hợp thực hành tại bắc giang
    Lớp học kế toán tổng hợp thực hành tại thái nguyên
    Lớp học kế toán tổng hợp thực hành tại thái bình
    Lớp học kế toán tổng hợp thực hành tại nam định
    Lớp học kế toán tổng hợp thực hành tại thanh hóa
    Lớp học kế toán tổng hợp thực hành tại tphcm
    Lớp học kế toán tổng hợp thực hành tại bắc ninh
    Lớp học kế toán tổng hợp thực hành tại hà đông
    Lớp học kế toán tổng hợp thực hành tại long biên
    Lớp học kế toán tổng hợp thực hành tại thanh xuân
    Lớp học kế toán tổng hợp thực hành tại cầu giấy
    khóa học kế toán toán dành cho giám đốc và nhà quản lý
    công cụ dụng cụ
    thủ tục thanh lý tài sản cố định
    bảng cân đối kế toán
    thuế thu nhập cá nhân năm 2015
    phần mềm htkk 3.3.1

  2. nice article in your blog.thank you for sharing useful info.
    web programming tutorial

  3. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    Selenium with python Training in Electronic City

  4. This is really an amazing blog. Your blog is really good and your article has always good thank you for information.

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

  5. Excellent Post as always and you have a great post and i like it thank you for sharing

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีหวยให้คุณได้เล่น สมัครหวยออนไลน์ ได้เลย
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688


  6. شركة نقل عفش من الرياض الى الامارات شركات نقل عفش من الرياض الى الامارات
    شركة نقل عفش من الرياض الى الاردن شركات نقل عفش من الرياض الى الاردن

    شركة نقل عفش من الرياض الى المدينة المنورة شركة نقل عفش من الرياض الى المدينة المنورة
    شركة نقل عفش من الدمام الى مكة شركة نقل عفش من الدمام الى مكة


    Thanks for sharing excellent information. Your web-site is very cool. I’m impressed by the details that you have on this site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found simply the information I already searched all over the place and simply couldn’t come across. What a great web-site.

    www office com setup 365