April 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Write Your First Android App with Eclipse

  • March 30, 2012
  • By Jessica Thornsby
  • Send Email »
  • More Articles »

In this tutorial, you'll develop a basic app for Android 4.0, aka Ice Cream Sandwich. You'll also learn how to modify the XML to add different types of buttons to your app. Finally, we'll move onto something more complicated: creating a clock widget and altering the location where this widget appears on the home screen.

To follow this tutorial, you'll need to install some software. The great thing about developing for Android is that everything you need can be downloaded for free:

  • Eclipse (if you're new to Eclipse, the Eclipse Classic package is recommended)
  • Android SDK
  • The ADT Plugin for Eclipse (this can be downloaded through Eclipse's Update Manager. If you're new to Eclipse, the Android Developers website has all the information you need to add ADT to your Eclipse installation)

Create a New Android Project

The first step is to create a new Android project. Open your Eclipse installation, and let's get started!

1) Open the File menu. Select New followed by Project.

2) In the New Project wizard, select Android followed by Android Project. Click Next.

ADT Plugin

3) Enter a name for your project (in this example, we'll use AndroidApp) and select the location where your project will be stored. Click Next.

ADT Plugin

4) Enter a build target -- this must not be greater than the target used by the Android Virtual Device (AVD), which is used to configure your Android Emulator. Click Next.

ADT Plugin

5) On the Application Info page, enter the following information:

  • Package name
  • Create Activity
  • Minimum SDK

After you have entered this information, click Finish.

ADT Figure 4

You have just created your first Android project.

Create Your Android App

You are now ready to create a basic Android app.

In Eclipse's Package Explorer, open the res folder, followed by layout andmain.xml.

ADT Figure 5

The big advantage of declaring your UI in XML is that it helps to keep the presentation of your app separate from the code that controls your app's behavior. For this reason, we will be solely working with XML in this tutorial. At this point, your XML code should read like this:

{?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:orientation="vertical" }

 

 {TextView
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/hello" /}

{/LinearLayout}

But how will this look on an actual Android device? The Android SDK includes a mobile device emulator, which allows you to quickly and easily test your app without ever leaving the development environment. To see your app in action, make sure the AndroidApp folder is selected in Eclipse's Package Explorer, and select Run from the menu.

ADT Plugin

Tip: The Android Emulator can take a few minutes to load, so be patient!

After the Android Emulator has finished loading, you can see your basic app in action.

ADT Plugin


Tags: Eclipse, Android development



Page 1 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel