Answer My Question Game Part 2: Setting Up the Project and Some Basic Concepts


[![](http://supermekanismo.files.wordpress.com/2012/02/droid.jpg?w=300)](http://supermekanismo.files.wordpress.com/2012/02/droid.jpg)
The droid mascot because.. well why not?
_Check out the other parts [here](http://krisviceral.com/tag/ams/ "AMS Tutorials"), description, status and source code [here](http://krisviceral.com/projects/ams-info/ "Info and source code"). Click on an image to enlarge (or use [this](https://chrome.google.com/webstore/detail/nonjdcjchghhkdoolnlbekcfllmednbl "Hover Zoom in Chrome") Chrome Extension to hover zoom)._
So with part 2 of the tutorial, let's set everything up and explain the working environment. First, go to file then select new Android project. In the first window type in whatever project name you desire then press next. In the following window you'll see a list of Android versions to target. According to data from Google, more than half of Android users are on [Gingerbread (2.3)](http://developer.android.com/resources/dashboard/platform-versions.html) so let's target that.

Once you go to the next screen, you'll be prompted to input a package name and Main Activity name. If you don't happen to know, package names are supposed to be the reverse URL. I don't have the domain name yet (Promise to buy it soon!) but leave it to whatever you desire for now. Also, I renamed the activity to AMS and not AMSActivity because that looks terrible. But wait! What are Activies?..

[![](http://supermekanismo.files.wordpress.com/2012/02/androidproject2.jpg?w=300)](http://supermekanismo.files.wordpress.com/2012/02/androidproject2.jpg)
Snippets of the project details creation.

**

** What are Activities in Android?

Basically, an activity is a 'window' for which the user can interact with. It takes care of creating the UI for you. Activities also have states to them. If you've tried using an Android application before then you might notice how an application is 're-created' when you go back to the homescreen or switching between another app. That is part of the lifecycle of an Android Activity. I'll give more information as we go along but if you want to read all about it then read about it from the documentation (Fret not! It's easy to read!).

[![](http://supermekanismo.files.wordpress.com/2012/02/activity_lifecycle2.png?w=233)](http://supermekanismo.files.wordpress.com/2012/02/activity_lifecycle2.png)
An activity lifecycle. More info and [source](http://developer.android.com/reference/android/app/Activity.html).
Going back, once you're done you should have a new folder created in your package explorer. The contents should be similar to the screen below.
[![](http://supermekanismo.files.wordpress.com/2012/02/packageexplorer2.jpg?w=266)](http://supermekanismo.files.wordpress.com/2012/02/packageexplorer2.jpg)
The contents of your project.
As you expect, the src folder will contain your packages and source code. The gen folder contains stuff generated by android and the Android 2.3 the packages, etc. The only other folder to play around with is the res and assets folder. From what I read, assets contain things like fonts or other similar things you will import in your program.

The res folder is where you will set most of your projects properties. In the layout folder, you create the UIs in XML. In the values folder, you can define string, color or other resource values. The Android Manifest holds most of your projects properties like permissions, version number, etc.

Permissions

Permissions are your applications way of asking to perform specific actions from the device. Some of these actions include using the Camera, reading and writing contacts, etc.

[![](http://supermekanismo.files.wordpress.com/2012/02/hello_worldandroid.jpg?w=300)](http://supermekanismo.files.wordpress.com/2012/02/hello_worldandroid.jpg)

Hello World and XML

Open the main.xml file in the layout folder. Congratulations! Just by doing nothing you already get a hello world message! The screen you see is what your application currently looks like (which is bland and boring of course). These XML files are the UIs that you can use in your program. You can also feel free to do it purely in-code if that suits you.

Before we start coding (and I know I'm already itching too), let's look at the working environment for UIs.

[![](http://supermekanismo.files.wordpress.com/2012/02/androidui.jpg?w=300)](http://supermekanismo.files.wordpress.com/2012/02/androidui.jpg)
Working with XML in Android. Click to zoom.
I marked 4 general areas of interest. The first one is the area where you can set the current representation of the UI. You can select the screen size or define your own. Also, you can set the orientation and select the theme to use (more on this later). In section 2, you can see UI elements you can use. Text fields, buttons and the likes are also represented. It's a drag and drop affair for adding elements.

Section 4 is probably the most useful part. You can see all the properties of the XML file from this section. So instead of memorizing properties, you can just look it up and sometimes there is a drop-down button of sorts to help you choose a preset value. (I wish I knew it earlier but hey you benefit from my mistakes).

Section 5 not seen in the screen shot is below section two. You can see two tabs named "Graphical Layout" and filename.xml. You can manually set values or create the UI through code if you so prefer.

The part where we code

Since you're reading this, you already have the slightest idea how to code so I don't need to tell you that clicking the src along with a file will open up the editor. In the next post, we'll finally start coding! Hooray! I'll hopefully still be able to discuss more important concepts as we go.

Stay tuned!