Android Development for Beginners


A colleague of mine asked for a quick tutorial on getting started on Android. So here it goes.

This will assume you have some understanding of how to develop using Eclipse and Java. If you already have that under your belt then all that is left is setting your environment and learning the Android APIs.

Android Development for Beginners – The Android Environment

You might find yourself finding articles and posts asking if one should use Eclipse, IntelliJ’s IDEA CE or Android Studio. Each has there own set of strengths and weaknesses if you choose to use them.


Eclipse is probably the most used and supported IDE available. Because of this I would recommend starting off your Android development experience using Eclipse. Most of the examples and screenshots you will see will be based on Eclipse. If you have problems or questions with the environment you will find more information with Eclipse then any other platform.

The downside is that it is a little clunky (for a lack of a better word). My biggest gripe with the IDE is the build errors that occur when refreshing the project structure. A co-worker might add a new library reference or change the project properties that will in-turn causes Eclipse on your machine to fail to build. Some times you will need to go through a laundry list of actions to correct your environments caching of the old configuration. Other times you will need to remove projects from your workspace and then re-import them.

IntelliJ IDEA

IntelliJ IDEA is in second place for the most used and supported IDE. IDEA is primary a Java IDE with Android Plugins available. This environment is my environment of choice. I used eclipse for about 2 years before switch off to IntelliJ. The IDE is cleaner and less clunky than Eclipse. The transition was fairly painless. Setting up the project workspace and references was different but manageable. The benefits out weighed the costs of switching.

The primary downside is that help with IDE specific issues is going to be limited. You will find yourself resorting to Stack Overflow for resolving problems you might have. Also, there might be some third party plugins that are not available I would say once you get a hold on android development then switching off Eclipse to IntelliJ IDEA is fairly straight forward.

Android Studio

The Benefit of using this environment is that it is built specifically for Android development. That is as far as I can go with the IDE’s pros.

Android Studio is basically a fork of IntelliJ’s IDEA platform and extended just for Android. I would recommend against using this environment for only beta testing the platform itself. If you have a problem that hinders your ability to complete your work it will be difficult to get a resolution. You might be the first person experiencing that issue. That doesn’t bode well for getting your work done.

At the time of this article, Android Studio is still in Early Access Preview at version 0.5.5. This has been in beta for almost a year. Unfortunately, there is no road map or time table for when this environment will be ready for prime time.

Android Development for Beginners – Getting Started

There is no better place then getting the information right from the horse’s month. Google’s Android Getting Started is a fantastic place to start.

Before you can start you need to get your development environment setup. You can download the Android Development Toolkit Bundle from the Android development site for free. This bundle contains Eclipse IDE and the Android SDK.

Note: The package includes a tools that is used for updating your Android SDK called the SDK Manager. This is used for updating your environment with the latest SDKs, emulators and supporting libraries.

Once you are finished downloading the bundle follow these instructions to get it setup on your machine. Also note you might need to use the SDK Manager update your SDK libraries and android emulators.

Android Development for Beginners – The Hello World Example

We are going to use the windows platform and eclipse IDE to walk through our Hello World example. If you use Linux or OSX your mileage may vary.

1) Open Eclipse and select Android Application Project

New Android Project

Eclipse – Choose a new Android Project

2) Setup your new Application Name, Project Name, and Package Name.

The Application Name is what will show up in the Google Play Store. The Project Name is a friendly name for the eclipse project itself. The Package Name is the base package name for your application code. It will also unique identity your application from others.

Here we targeting a minimum Android SDK API 2.2 which will allow this app to support 98% of all android devices.

Note: Targeting anything less than API 3.0 will not allow you to HIG controls such as Fragments or the popular Action Bar

Eclipse - New Android Application

Eclipse – New Android Application

3) Setup Project Specific Settings

This is just a project setup helper step. This step just enables the wizard to further setup this project’s initial artifacts. The following setup will ask how to setup the activity, app icon and the xml layout resource used to for the initial view.

Eclipse - New Android Application Project Settings

Eclipse – New Android Application Project Settings

4) Your Application Image setup

What you see here, mdpi, hdpi, xhdpi, xxhdpi types, are all different images sizes for different screen pixel density screens. This is much like iOS’s @x2 annotations to denote retina images. You don’t need to support every screen density but it is good practice to do so. If an image is not available for a specific screen density then it will grab the next best available.

Eclipse - New Android Application Project Image

Eclipse – New Android Application Project Image

5) Initial Activity Selection

Here we are selecting the blank activity. Notice the other options available. The Fullscreen Activity just configures the activity not to have a title bar via the Manifest.xml file config.

The Master/Detail Flow sets up the application to use activity fragment in the main view. Since we are targeting a minimum SDK of 2.2 (or anything under 3.0) we cannot use the fragment implementation as noted in the warning if you attempt to select it.

Note: Pre 3.0 (Honeycomb) Android API can support fragments, action bars, etc, but it must be implemented using the Android Support Library. This library released by Google exists to help older devices implement the newer look and feel in applications.

Eclipse - New Android Application Project Activity Selection

Eclipse – New Android Application Project Activity Selection

6) Setup Your Initial Layout

Here you will see the naming of your initial layout. This will be the name of the xml layout (the view definition) that will be inflated then the initial activity, MainActivity, is created.

After this setup your first application will be ready for deployment. At this point, assuming your emulator is setup or you have a device you can run your app for the first time.

Eclipse - New Android Application Setup Your Initial Activity

Eclipse – New Android Application Setup Your Initial Activity

7) Your Android Project

You should take note of several key components of the project source. The package com.iteedee.helloworld package name is where the project houses the activity files. The res folder which contains the application images and layout views.

Note: You will notice the MyHelloWorldApp is not the only project in this workplace. The android-support-v7-appcompat project is the android support library for pre-honeycomb support.

Eclipse - New Android Application Project Structure

Eclipse – New Android Application Project Structure

Android Development for Beginners – The Basic Android Artifacts

App Manifest.xml

The Manifest.xml file describes and stores essential information about your app. The file is used to store the following information:

  • Your apps target and minimum SDK versions.
  • Your apps package name, version code and version number.
  • Where you register all of your activity classes.
  • Permissions your app will need from the OS to run.
  • The processes that will be hosted by this application.
  • The libraries the app is linked against.


As Google describes an activity:

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.

As mentioned above, all activities are registered in the manifest file. An activity is the all encompassing implementation for handling the UI and its life cycle. Most of your UI logic lives or will be referenced in an activity.

An Activity also handles the life cycle of a view. To get a better idea of what the life cycle of an activity looks like I have provided a workflow chart below:

Android Activity Workflow

All of the activity life cycle events are important but for the sack of this article we will focus on onCreate().

public void onCreate(Bundle savedInstanceState)
        // load the layout

The setContentView(R.layout.activity_main) method call causes the activity to inflate the xml view. If you are needing logic to setup your view this is a good place to implement it.


The first time you will need to use an intent is when you want to navigation the user to another activity. Intents are used to communicate data between activities by using bundles. They are also used to describe how an activity gets push or popped on the navigation history using Intent Flags.

It is also important to note that you can register to get a result when an activity finished via intents. This is helpful when a parent activity needs to know information about what happened when a child activity finishes.

Layout Resource

Android maintains all of their view definitions as resources. They can be found in the res/layout folder. Android layout views are xml definitions that use many different ViewGroups to structure the layout of the view. If you are familiar with Microsoft’s XAML or Adobe Flex’s MXML then understanding how android defines the views should be a breeze.


Controls that are required to interact with data sets do so using Adapters. Controls such as a ListView interacts with the adapter you assign to it. The adapter in turn has logic to “Bind” each item in the data set to each ListView Row’s view.

An adapter tell the control how many items are in the data set. It also supplies an inflated view for each item that control need by the data set’s index. You can find a great example of setup an Array Adapter here

ViewGroup and Views Controls

When building your XML Layouts you will need to understand the difference between a View and an ViewGroup.

A ViewGroup is a view that can contain other views or view children. Common ViewGroups are AbsoluteLayout, FrameLayout, GridLayout, LinearLayoutRelativeLayout and ViewPager.

A View is a UI Control (that isn’t a ViewGroup) that cannot contain other defined views. Views don’t adhere to a composite view pattern like ViewGroups do. Common Views are ImageView, ProgressBar and TextView.

Note: Many other views inherit from TextView such as Button, EditText or Checkbox.

Both Views and ViewGroups will always need their Layout Parameters defined. Layout_width and Layout_Height is required and must be one of the following: FILL_PARENT, WRAP_CONTENT or the exact size you want. As Google explains it:

  • FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding)

  • WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding)

Programmatically Interacting with the View from the Activity

A common question most developers will have when starting on Android development is “How do I reference and programmatically change the view from code?”

This is straight forward. Every class that inherits from activity will have a method called findviewbyid(int). Additionally, if you want to handle events from controls in the view then simply supplying the method name of the activity’s event handler is all that is required.

Lets create have a simple view. Take note of the android:id="@+id/txtCurrentTime" and the onClick="btnUpdateTime_Click" property in each of the views.

    <TextView android:id="@+id/txtCurrentTime"
    <Button android:id="@+id/btnUpdateTime"
            android:text="Update Date Time"


Your activity needs to have a public method named btnUpdateTime_Click. In the activity we are handling the click event and setting the TextView with the current date and time:

public void btnUpdateTime_Click(View v)
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();

Notice the activity’s method this.findViewById ios used to get a reference t the view. Since it will only return a type of View we need to cast it to a TextView and call the setText method.

All views are referenced by resource id, not the string name. The @+id in @+id/btnUpdateTime tells the resource class generator to register a resource for that id.

Some Additional Resource to review

Let me know below if you have any questions or have anything to add.

Posted in Android and tagged , , , , , , .