Home » Android » Android Games » Android Game Development – Create The Project

About Impaler

Android Game Development – Create The Project

Now that we have our idea let’s get the environment up and start coding.

To install Android follow the steps found on the official documentation page. I use eclipse so if you are a Java guy it should be pretty familiar. If you have never developed in Java but did some other coding in C++ or C# for example it should be pretty simple to catch up. I would recommend starting with some Java tutorials and then switch to Android. If you haven’t programmed before…well that’s though but it’s solvable. Google for some programming tutorials and don’t get discouraged! Then check back here.

I will use Android 2.2 as it is the latest at the time of this writing and I suspect it will take a long time till I finish this project so it just might be quite used. Also because we plan to use multi-touch we need version 2.x.

First let’s create the AVD (Android Virtual Device). Click on the little Android icon or choose Window -> Android SDK and AVD Manager and click on the New… button.

Set the name to MyDevice, the target to Android 2.2 – API Level 8. Set 128 MiB for the SD Card. Set the Skin to Built-in HVGA and the Hardware to Abstracted LCD density to 160. These are the current default settings.

Click Create AVD and the virtual device should be created.

Now let’s create the project.

Select from the menu: New -> Project and choose Android Project.

Fill in as per the screen-shot and click Finish.

The Application name is the name given to our game. The package name is just the name space to group our classes.

Select Android 2.2 for Build Target.

The most important is the Create Activity. The Activity is the class instantiated when the application is started. Don’t have to worry about it right now just remember that is the first thing being called.

In a nutshell the Activity handles our input (gets the touches on the screen), creates the window where we will display our game and so on. This usually is a full screen window and we will use one as such.

Let’s run the created application. Right click on the project and choose Run As -> Android Application. Choose the configured device and wait for it to load. Remember not to close the Virtual Device once it has started as every time you will run your project, eclipse will redeploy it to the currently running device and will save you a lot of time if it’s already started.

You should see a screen like the one below. If the device asks you to unlock the screen do it by dragging the unlock button with your mouse.

Now let’s examine what has just happened. Open the DroidzActivity.java file.

package net.obviam.droidz;

import android.app.Activity;
import android.os.Bundle;

public class DroidzActivity extends Activity {
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

You’ll notice one method. The onCreate() method on line 09. This method is called when the activity is being created at the application launch. It’s sets the view (the display) to be the default R (check R.java) which is the default resource view automatically generated by the android tools behind the scenes.

This file feeds on multiple configuration files to provide the activity with the view. It reads the main.xml from the res (which stands for resources) directory and parses it.

Let’s open the res/layout/main.xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

You’ll notice that a LinearLayout is used that fills up the whole screen and has a vertical positioning (Line 2). Line 3 tells that our orientation is horizontal while lines 4 and 5 instruct android to use the whole display (currently the parent is the display) for the view.

Line 7 defines a TextView which is just a label that takes up a whole line of the contained text’s height. The value is a placeholder read from the @string file. @string is also a placeholder for the strings.xml file and opening this file you’ll immediately notice that this is the place where the actually displayed value comes from. Worth noting that the R.java file is regenerated after we modify strigs.xml and for each resource entry a corresponding constant is generated and it will be used internally.

Open the /res/values/strings.xml file:

<?xml version="1.0" encoding="utf-8"?>
    <string name="hello">Hello World, DroidzActivity!</string>
    <string name="app_name">droidz</string>
    <string name="warning">Robots are rising</string>

These are the resource strings. Apart from line 5 which I added everything is generated. To add the warning message to the display just after the hello message modify the main.xml file and add a new TextView that will display our @warning message.

The new main.xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

If you run the activity then you should have a screen displaying the new warning message too.

Worth noting that eclipse regenerated the R.java file and if you open it you will notice a similar line to this:

public static final int warning=0x7f040002;

It is generated by the android tooling and it keeps the IDs and pointers to the actual resources that are used in the activity.

Go ahead and play with the current setting and see what the options are for different display widgets.

Next we will actually load some images and draw them onto the screen.

Reference: Creating the Android Project from our JCG partner Tamas Jano from “Against The Grain” blog.

Do not forget to check out our new Android Game ArkDroid (screenshots below). You feedback will be more than helpful!
Related Articles:

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....



  1. motivational stuff…thanks !! 

  2. I get the following error when I try to run the project the first time:

    Errors occurred during the build.
    Errors running builder ‘Android Package Builder’ on project ‘Test1′.

    I created the AVD per the instructions.

  3. ohh, thank you for tutorial..
    nice., very helpful.

  4. Many of the tutorials I have seen online use a game engine to develop games. Should I worry about using game engines as a beginner?

    • You don’t have to worry about using game engines as a beginner and even if you are a professional.
      It may be good to use game engine or even to make you own game engine if you decide to make just one sort of games (for example: FPS, 2D platform, etc.) but you have to calculate is it profitable, and usually the big companies do that.
      But the things that are very helpful are game libraries. For example: OpenGL and LWJGL for graphics; JBox2D for 2D physics, etc.

  5. With these 3 strings, I also have 1 more string: menu_settings and if I remove it, an error occurs… And also, when I created the DroidzActivity, it generated 2 methods instead of 1: onCreate (in common) and onCreateOptionsMenu (which I have deleted and it works normally without it)…. Can you please help me with this? Have I done something wrong so this string is generated too or what?

  6. thanks! this really helped!!!

  7. This is super cool (for that time when was first published). I am looking at it 2 years later (sigh) and sadly, there are of course, lots of different things.. files renamed, location of files, definitions and so on… sometimes I wonder if it’s worth to have a published tutorial for more than 6 months :-)

    Still pretty good stuff here, thanks.

    • Also, with the newest and greatest ADK, the fragment_main.xml is not defining the LinearLayout anymore, but instead, RelativeLayout. When I added the second TextView, it is displayed on top of the first string so I had to resource to the graphical view to figure what was happening… plowing through the things is more like it :-)

  8. how to download the software and how to make the project of game application

  9. Nice keep us informed thanx
    thanx for sending me email

  10. Send me info about new books on my mail

Leave a Reply

Your email address will not be published. Required fields are marked *


four + = 7

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.