-
Android Application Development: Day 1-4: Building a Music App - Part 1
Building Blocks
Downloading the SDK Platform
As mentioned before, you should have a basic knowledge of Java before attempting this tutorial.
If you don't have much Java exposure, start here.
If you are picking up from Day 3, feel free to close out of that welcome screen. You won't be needing it. Trust me.
If you don't have much Java exposure, start here.
If you are picking up from Day 3, feel free to close out of that welcome screen. You won't be needing it. Trust me.
The SDK Platforms
To create your first Android application, you must first have an SDK platform.
Open up the Android SDK Manager:
Open up the Android SDK Manager:
Oh look! The Bundle (Eclipse + Android SDK + ADT) includes the latest SDK Platform. So we won't be needing to download that; however, if you want to create emulators to test your application on lower versions of Android, you will need to download that here (you can do that later).
Creating your First App
Now that we discussed the logistics, let's create our first application. We will create a very simple music player that works as follows:
1. Select File >> New >> Android Application Project.
2. Enter the following value:
Name: Awesome Music Selector App
This will automatically fill the two boxes below.
2. Enter the following value:
Name: Awesome Music Selector App
This will automatically fill the two boxes below.
Leave the other settings as they are. The Target SDK should always be the latest version of Android. This lets you use the latest features available to Android in your applications.
3. Press Next.
4. Press Next Again.
3. Press Next.
4. Press Next Again.
I'm going to be using a custom icon that I have found on DeviantArt. Credits to arrioch who made this freely available.
![]()
|
5. On the Create Activity screen, leave BlankActivity selected, and press Next.
A lot of tutorials and books like to talk about every little detail of Android before you begin creating apps. What ends up happening is that you read a bunch of stuff that you intellectually understand but cannot conceptually visualize, and then you forget everything to learn it again after you start programming. So I will skip the traditional "before you begin" spiel about Activities, services, and so on, and we will talk about those things as they come up.
For now, think of an Activity as a page. Something that is visible to you.
Press Finish.
For now, think of an Activity as a page. Something that is visible to you.
Press Finish.
Running the Application
You might have some errors after creating the project. Let it sit for a few moments. The errors should disappear.
At this point, you can press Run to run your project, as an Android Application.
Once it finishes loading, you should get an error saying no compatible devices were found. Press OK.
You should see the Android Device Chooser. The upper part of this labeled "Choose a running Android device" will run all the Android devices connected to the computer with USB Debugging enabled (more on this later).
The bottom part of the Android Device Chooser lists all the Android Virtual Devices on your computer.
Click on Manager... to open up the Android Virtual Device Manager.
At this point, you can press Run to run your project, as an Android Application.
Once it finishes loading, you should get an error saying no compatible devices were found. Press OK.
You should see the Android Device Chooser. The upper part of this labeled "Choose a running Android device" will run all the Android devices connected to the computer with USB Debugging enabled (more on this later).
The bottom part of the Android Device Chooser lists all the Android Virtual Devices on your computer.
Click on Manager... to open up the Android Virtual Device Manager.
When the Android Virtual Device Manager opens, press New...
Fill out the form as below. This will create a virtual Galaxy Nexus for us:
Fill out the form as below. This will create a virtual Galaxy Nexus for us:
You can see that it emulates the type of processor, you can specify RAM size, and VM Heap size* (in MegaBytes).
Once you have the values that I have on my screen, Press OK.
(Snapshot lets you restart your emulator from where you signed off. It lets the emulator get started more quickly, so I recommend checking that).
*A quick note about heap: Heap usually refers to the amount of memory available to our application. Despite our device having 1GB of memory, only 64MB is available to our application. On some lower end devices, the heap size is 16MB. This is a problem that we did not have in the previous Units, but from now on, we will have to manage memory to make sure we do not fill up the heap (which activates the Garbage Collector and in worst cases causes an Out of Memory exception). I will discuss the GC and the exception in later lessons.
Now if you open the Android Device Chooser again and click Refresh, you will see the following:
Once you have the values that I have on my screen, Press OK.
(Snapshot lets you restart your emulator from where you signed off. It lets the emulator get started more quickly, so I recommend checking that).
*A quick note about heap: Heap usually refers to the amount of memory available to our application. Despite our device having 1GB of memory, only 64MB is available to our application. On some lower end devices, the heap size is 16MB. This is a problem that we did not have in the previous Units, but from now on, we will have to manage memory to make sure we do not fill up the heap (which activates the Garbage Collector and in worst cases causes an Out of Memory exception). I will discuss the GC and the exception in later lessons.
Now if you open the Android Device Chooser again and click Refresh, you will see the following:
With our virtual Galaxy Nexus selected, press OK.
NOTE: You might get an error saying:
Failed to allocate memory: 8 This application has requested the Runtime to terminate it in an unusual way.
NOTE: You might get an error saying:
Failed to allocate memory: 8 This application has requested the Runtime to terminate it in an unusual way.
To Work around This:

Open up the Android Virtual Device Manager again.Select GalaxyNexus, and press the Edit... to the right.
Now change the RAM to 512, and press OK.
Exit out of AVD.
This should fix the issue (an annoying bug in the Android SDK). Press Run again.
Now change the RAM to 512, and press OK.
Exit out of AVD.
This should fix the issue (an annoying bug in the Android SDK). Press Run again.
Now wait for a very long time.
It takes a very long time for the emulator to get started up. Let it sit for anywhere from 1-10 minutes. If you have the Snapshot option enabled, your emulator should start up much faster the next time.
Developers usually keep the emulator minimized so that they do not have to start it up every time they make a change to the application.
Developers usually keep the emulator minimized so that they do not have to start it up every time they make a change to the application.
When you see this screen...
You have successfully created your first Android project, setup a virtual Galaxy Nexus, and ran the program... all without writing a single line of code!
(If you get a popup about LogCat, you can say OK).
Congratulations! You took a small step into the world of Android.
We will be developing this project further in the next lessons.
(If you get a popup about LogCat, you can say OK).
Congratulations! You took a small step into the world of Android.
We will be developing this project further in the next lessons.
Feel free to email me questions at jamescho7@kilobolt.com
|
|

No source code is available for this lesson.
comments powered by Disqus