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? |
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). |
[![](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. |
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.
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. |
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.