Android is now one of the most popular smartphone/mobile operating system in the world. This tutorial will help you on creating your first android application (Hello World application) using Eclipse IDE and Android Development Tools (ADT) and also Android Virtual Device (AVD) or your real android device to run the application.
Tools used in this tutorial:
1. JDK 1.6
2. Eclipse IDE
3. Android SDK
I suggest you to use ADT Bundle so installing ADT plugin in Eclipse is not required. You can download it here ADT Bundle
1. Create Android Project
Select File–>New–>Other–>Android Application Project and click Next Button
2. Configure Project Settings
Enter your Application Name, Project Name and Package Name. Select Minimum Required SDK, the lowest version of Android that the application supports. Target SDK, the highest version of Android. Compile With, android version which the application will be compiled with. And Theme. If you are not sure, just leave it as it is. Click Next.
Click Next again
3. Configure Launcher Icon
Create you launcher icon as you want or as you requirements need. In this tutorial i have changed few default settings.
4. Create Activity
Choose an activity BlankActivty template and click Next. An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI.
Enter Activity Name and click Finish
5. Project Structure
Here is the project structure generated by the IDE
the layout file (activity_hello.xml) is shown in the Graphical Layout mode as follow
6. Code
Open string.xml and there is string property with name hello_world which contains value as ‘Hello world!’ that is used by TextView to be shown in our application.
file : string.xml
1 2 3 4 5 6 7 |
<resources> <string name="app_name">HelloWorld</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> </resources> |
Open activity_hello.xml and you should see the
file : activity_hello.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout> |
And here’s our activity
file : MainActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package com.agung.android; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class HelloActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_hello, menu); return true; } } |
We don’t need to change any code yet.
7. Run Configuration
Right click on the project and select Run As–>Run Configurations. If there is no AVD already created, create it by click Manager
Configure AVD as you wish or follow like below
8. Run Application
Right click on the project and select Run As–>Android Application
9. Running Program
Eclipse will running AVD and our application should be there.
Click on Hello World icon, and here’s what our application looks like, very basic application
ahh. thank you gan :D. its work.. tambah lg dong tutorialnya. hhee.. btw td untuk MainActivity.java atau string.xml gt, sempet bingung tmpatny dimana. mgkn bisa diperjelas lg nntinya
😀
iya ntar nyusul tutorial yang lain hehe
MainActivity.java sama strings.xml itu bawaan hasil generate Eclipse pas pertama bikin project
MainActivity.java bisa ditemukan di src/nama_paket/MainActivity.Java (pada contoh diatas nama_paket-nya com.agung.helloworld
Sedangkan strings.xml bisa dilihat di res/values/strings.xml