• Home
  • Tutorials
    • Game Development Tutorial>
      • Unit 1: Beginning Java>
        • Before you begin...
        • Day 1: Setting Up
        • Day 2: Java Basics
        • Day 3: More Basics
        • Day 4: Java Math
        • Day 5: More Math
        • Day 6: If... else...
        • Day 7: More Control Flow
        • Day 8: Looping
        • Day 9: More on Looping
        • Day 10: Inheritance, Interface
        • Day 11: Threads and Graphics
      • Unit 2: Creating a Game I>
        • Day 1: Foundations
        • Day 2: Basic Framework
        • Day 3: Taking User Input
        • Day 4: Enter the Robot
        • Day 5: Background and Sprites
        • Day 6: Adding Enemies
        • Day 7: Shooting Bullets
        • Day 8: Animations
        • Day 9: 2D-Arrays
        • Day 10: Painting the Tilemap
      • Unit 3: Creating a Game II>
        • Day 1: Level Creation - Part 1
        • Day 2: Level Creation - Part 2
        • Day 3: Level Creation - Part 3
        • Collision Detection Basics
        • Day 4: Collision Detection Part 1
        • Day 5: Collision Detection Part 2
        • Day 6: Collision Detection Part 3
        • Day 7: Health System & Death
        • Day 8: Basic AI & Final Touches
      • Unit 4: Android Game Development>
        • Day 1: Introduction to Android
        • Day 2: Setting up for Development
        • Day 3: Creating our First Android Application
        • Day 4: Parts of an Android Application
        • Day 5: The Android Game Framework: Part I
        • Day 6: The Android Game Framework: Part II
        • Create an Android Game From Scratch (or port your existing game)
        • Day 7: Creating an Android Game (From Start to Finish)
      • Reference Sheet
    • Zombie Bird Tutorial (Flappy Bird Remake)>
      • Unit 1: Building the Game>
        • Introduction
        • Day 1: Flappy Bird - An In-depth Analysis
        • Day 2: Setting up libGDX
        • Day 3: Understanding the libGDX Framework
        • Day 4: GameWorld and GameRenderer and the Orthographic Camera
        • Day 5: The Flight of the Dead - Adding the Bird
        • Day 6: Adding Graphics - Welcome to the Necropolis
        • Day 7: The Grass, the Bird and the Skull Pipe
        • Day 8: Collision Detection and Sound Effects
        • Day 9: Finishing Gameplay and Basic UI
        • Day 10: GameStates and High Score
        • Day 11: Supporting iOS/Android + SplashScreen, Menus and Tweening
        • Day 12: Completed UI & Source Code
    • Android Application Development Tutorial>
      • Unit 1: Writing Basic Android Apps>
        • Before you begin...
        • Day 1: Android 101
        • Day 2: Getting to Know the Android Project
        • Day 3: The Development Machine
        • Day 4: Building a Music App - Part 1: Building Blocks
        • Day 5: Building a Music App - Part 2: Intents
        • Day 6: Building a Music App - Part 3: Activity Lifecycles
  • New Forum
  • About Us
    • Contact Us
  • Our Games
    • TUMBL: FallDown
  • Facebook
  • Twitter

        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.

The SDK Platforms

To create your first Android application, you must first have an SDK platform.

Open up the Android SDK Manager:
Picture
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:
Picture
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. 

Picture
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. 
Picture
I'm going to be using a custom icon that I have found on DeviantArt. Credits to arrioch who made this freely available.

Picture
icon.png
File Size: 6 kb
File Type: png
Download File





5. On the Create Activity screen, leave BlankActivity selected, and press Next.
Picture
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.

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.
Picture
When the Android Virtual Device Manager opens, press New...

Fill out the form as below. This will create a virtual Galaxy Nexus for us:
Picture
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:
Picture
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.

To Work around This:

Picture
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 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.

When you see this screen...

Picture
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.
Feel free to email me questions at jamescho7@kilobolt.com

Picture
No source code is available for this lesson.
Go to Unit 1: Day 3
Go to Unit 1: Day 5
comments powered by Disqus
© 2014 Kilobolt, LLC. All rights reserved.