This post is the last part of a three-part series of tutorials for getting started on Android development. Check out the previous entries here:
On our previous post, we've already set-up our Eclipse IDE and Android SDK. What's next? Well, let's get into the thick of things and develop our first Android application!
We'll be developing a simple application that shows "Hello, world!" to the user. As such, we'll name it HelloAndroid. It's boring and common, but then that's the only thing that's boring about Android development. Let's go!
GOING DOWN TO BUSINESS
After starting up Eclipse, we move right into action by creating a new Android Application Project. From our menu bar, click on File > New > Project..
A New Project dialog pops up. From here, expand the Android folder and select Android Application Project. Click Next.
For the next screen, we're presented with a good number of fields and options. I'll try breaking them down one by one:
Application Name
This will be used as the name of the application throughout the Android operating system. The entry will be seen under the application's icon in the Android application drawer, as well as entries in Google Play. This can be changed later in the Android Manifest file, but we'll get to that in a future post.
Project Name
This name will be used in your Eclipse workspace. This identifies the speficic Android project, since Eclipse does not allow duplicate project names for the same workspace.
Package Name
This is a set of words separated by dots that uniquely identify your application. Think of this as your unique application ID. Package names cannot be duplicated when publishing to Google Play, so make sure this one is unique to you and your application.
Minimum Required SDK
Select the minimum SDK that would be required of Android devices in order for your application to run. Devices running any SDK lower than this cannot search for your application in Google Play.
Target SDK
The SDK level that you develop your application on - meaning, this is the SDK level that you're application is known to work on, with the most features and the least issues.
Compile With
Usually targeted at the latest available API, or the API that your application has been tried to run on and successfully did.
Theme
This makes you select different themes for your initial application.
That about sums it up. In a nutshell, here are the entries we'll be using for this tutorial:
Application Name: Hello Android
Project Name: Hello Android Project
Package Name:com.helloandroid.sample
Minimum Required SDK: API 8
Target SDK: API 14
Compile with: API 17
Theme: Holo Light with Dark Action Bar
(Make sure you've downloaded the appropriate API from the SDK Manager)
Click on Next.
For the Configure Project screen, click on Next.
On the Configure Launched Icon screen, you can just click on Next. Or you could play around with any icon, this won't really matter for now.
For Create Activity, make sure that Create Activity is ticked, and BlankActivity is selected. Click on Next.
On the New Blank Activity dialog, just click on Next. This is the part where we'll name our Activity file, but the pre-populated entries will do.
For the next screen, Eclipse will check for the presence of your dependencies. If they haven't been installed, just click on the Install/Upgrade then follow the next steps. After which, click on Finish.
You've just created a new Android Application Project! For the most part, all the needed files have been generated and prepared for us to display a Hello World! text to our application's users. If you did the above steps correctly, the left part of your Eclipse should look like this..
...while the main window of Eclipse would like something like,
RUNNING OUR APPLICATION
Since most of the world has already been done, what's left is for us to compile our application and have it run.
Basically, there are two ways to run your application. First is by having a physical Android device plugged into your machine and have the application run there right away. This would involve a few more configuration steps, but we won't be using this method for now.
The second way would be to run an Android Virtual Device, more commonly referred to as AVD. An AVD is basically an emulator that runs on your machine, no different than running a virtual machine like Mac OSX or Linux Ubuntu. If you're familiar with VMWare or VirtualBox, you'll find that the concept are very much alike.
For now, we'll go through the steps in running the AVD. Remember that icon we saw that led us to the SDK Manager? Now, we'll use the icon right beside it.
This opens up a dialog box,
Click on New.., opening up another window. This time, just fill in the entries as shown below.
Click on OK. This will take you back to the AVD Manager window, but an additional entry will be present. Select this entry and click on Start.., then Launch.
Wait for the emulator to finish booting, and you should get something that looks like this:
Now that we have that running, let's go back to Eclipse. On our Project Manager window. (the one on the left), right-click on the project name (in this case, Hello Android Project) and select Run As > Android Application. This will automatically compile your application and run it on the AVD we just created. It can take a while to finish loading your application onto the AVD, but after it's done, it should look like this:
Congratulations! You've just run your first Android application!
Now, that's the east part. On the next posts, I'll take you through the code that allows us to run this application and show this text, as well as other things to keep in mind while developing for Android.
To check out the other posts of this series, click on the links below:
No comments:
Post a Comment