My First Android Program

It’s pretty exciting to write about developing first program in Android. In our first program, we are going to have an image and label on the Window.

Its a simple traditional ‘Hello World’ program.

Let us begin with it by opening new android project in eclipse.

Quick Links

Project Structure

Launch eclipse, open new android project in either of the two ways:

File >> New >> Others >> Android >> Android Project

File >> New >> Android Project

Click next and provide project name which is going to be your Activity Class name, so make sure your project name must suite your functionality of the application.

After providing project name, click next and choose Android target device version. You have to choose your device’s installed Android version.

Click next and provide package name. Package name must follow naming convention since a particular device will have multiple packages which should not be ambiguous at run time. So follow below mentioned naming scheme:

com.myapp.”Name of your app”

com.<name-of-your-company>.android.<name-of-the-app>

[pglinkadssmall1]

All done, you have successfully created ‘New’ android project. Let’s modify the default layout and add controls to the application we just created to bring an image – Android logo and label – Hello Android at the center of the device’s window as we discussed earlier.

Code Listings

To begin with layout modification, we need to add an image – Android logo to the resources folder and add text ‘Hello Android’ in strings.xml.

Expand Project folder >> res >> drawable-hdpi >> Place/Paste Android logo image

Expand values folder >> Open strings.xml >> Look for String ‘hello’ >> Add text ‘Hello Android’ to ‘hello’ string element

Open main.xml under res/layout folder and replace the xml with the below xml which has one image and one label aligned centrally.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/android_logo" />

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello" />

</LinearLayout>

Open ‘Graphical layout’ of the main.xml, you could see the design of our application. Graphical layout allows you to design application UI just by doing simple drag and drop the controls.

[pgsubscribe]
Make sure ‘Build Automatically’ option under Project menu is selected so that project will be built automatically every time after you did change.

Demo

That’s it, we need to run the program and check the output.

Right click on the Project >> Run as >> Android Application >> Select emulator [configured at the time SDK installation] or Your Android device

[pglinkadssmall]

Google installs ‘Emulator’ along with the SDK installation. It’s upto you whether you want to run the application in Emulator or in your android device. I would prefer to run my apps on my device since most of the services like GPS, Google inbuilt services, bluetooth etc are not supported in Emulator but still application will run without any issues in Emulator if your app doesn’t involve any of the aforementioned services.


You must enable ‘USB debugging’ in your mobile settings so that it will be acting as target device when connected to your PC. And its simple to run your app in Mobile device.
Here is our most awaited output:

Download Source Code

Entire project is zipped and is available for download. Unzip the downloaded project and to import the project into eclipse, launch eclipse >> File >> Import.. >> Choose downloaded project (How to import android project in eclipse). If you just want to run the application in your mobile and see the output but don’t want to hit your head with source code, download application(apk) file and install it in your mobile device.

Download Source Code Download Application(apk)

*apk in Android  is the installation file simliar to exe in windows.

Keep me posted with your valuable feedback. :)
Thanks for reading the post!!
Do share with your friends if you want to let others know about this content!!


[pgfeedback]
[pgwriteforus]

Author: Android Guru

Share This Post On
  • Bhavani Sridhar

    Hi,

    Really superb..:). Keep up ur good work..

    • http://programmerguru.com/android-tutorial admin

      Thanks for comment :)

  • Satheesh

    Nice……..

    • http://programmerguru.com/android-tutorial admin

      Thanks for the comment :)

  • Naresh

    Good to see you as a developer. Changeover from prod ops to dev..keep going :-)

    • http://programmerguru.com/android-tutorial admin

      Thanks Machi.. 😉

  • Maheedhar

    Good Work Bro… :)

    • http://programmerguru.com/android-tutorial admin

      Thanks man.. :)

  • Vijayababu

    Really good…

    • http://programmerguru.com/android-tutorial admin

      Thanks boss..

  • leninkumar

    Hi.. Is there any possibilities to get stand alone android application for my marketing team. Bcos everyday they met more people, i decided to allow them to enter customer info into local database (android Mobile / Tabletpc). How come i am going to synchronize all the data which is captured by team. How to prepare the reports.

    I am not a technical guy. But I need application. If i am getting help from your forum i am very grateful.

    My mail id : leninkumar@yahoo.com

    • http://programmerguru.com/android-tutorial Android Guru

      Hi Lenin,
      You should develop a custom android application to meet your requirements. You can create it by your own if you know something about Android programming. If not many companies are there who are developing Android apps,just contact them to convert your requirements to Android App. :)

  • Ganesh

    Created my first Android program. Thanks for the tutorial :)

    • http://programmerguru.com/android-tutorial Android Guru

      Welcome to Android world. :)

  • hemalatha

    good work…

  • Anand

    Is there any possibilities to use android applications in Nokia serbian Phone.

    • http://programmerguru.com/android-tutorial Android Guru

      Android applications cannot be run in platforms other than Android. If the applications are created/developed using framework like PhoneGap, they canbe run in all mobile platforms supported by PhoneGap. Follow this link: http://phonegap.com/ for more info.

  • safiullah

    hello sir can u send me or tell me this apllication site to my email ie(java escllipse).. plz sir

    • http://programmerguru.com/android-tutorial Android Guru

      Hi Safiullah, I have already discussed about ‘how to install eclipse’ as a separate post. Please take a look at Android – Basic setup and installation where you can find details about Eclipse site and installation too.

  • Jane

    hello everyone,, do i need to plug in my android phone to the computer while making this first app? thanks

  • http://programmerguru.com/android-tutorial/ Android Guru

    You also have an option to test your App in Emulator. All you need to do is configure Emulator in your machine. Here are the steps – http://developer.android.com/tools/devices/managing-avds.html

    If you wish to use your Android mobile for testing your App, make sure you enabled ‘USB debugging’ [Settings > Developer options] in your mobile and connect it to machine.

    Refer this link – http://developer.android.com/tools/building/building-eclipse.html#RunningOnDeviceEclipse for running app on device.

Join now to get more access to our Android Tutorials

Join now to get more access to our Android Tutorials

Once you Join, you will receive Mail containing latest Android Tutorials once a month !!

I promise I wont spam you !!

You have Successfully Subscribed!

Pin It on Pinterest

Shares