-
GAME DEVELOPMENT TUTORIAL: DAY 4-4: Parts of an Android Application
Welcome to Day 4 of Unit 4: Android Game Development.
We will pick up where we left off in Day 3. By now, you should have successfully created and ran your first Android project.
In today's lesson, we will discuss how you can use a real device for testing, and then we will discuss the important parts of an Android application.
No coding is necessary for this lesson (that's coming in the next lesson) so no need to get Eclipse started up (unless of course, you would like to follow along)!
We will pick up where we left off in Day 3. By now, you should have successfully created and ran your first Android project.
In today's lesson, we will discuss how you can use a real device for testing, and then we will discuss the important parts of an Android application.
No coding is necessary for this lesson (that's coming in the next lesson) so no need to get Eclipse started up (unless of course, you would like to follow along)!
Running Applications on a Real Device
If you have tried your hand with the emulator, you have probably noticed that it is not exactly a speed demon. When you want to test your game for responsiveness, it is not a great idea to use an emulator.
So you will probably be relying on a real device for testing. I personally use a Galaxy Nexus when I develop, and do compatibility checks with an old Galaxy S.
How does one use a real device with the Android SDK? Follow the steps below:
So you will probably be relying on a real device for testing. I personally use a Galaxy Nexus when I develop, and do compatibility checks with an old Galaxy S.
How does one use a real device with the Android SDK? Follow the steps below:
1. Enable USB Debugging
On your Android device, open up Settings. The location of the USB Debugging settings can vary. Here are some possible locations:
1. On earlier versions of Android, you could find it by selecting Applications and then Development.
Check that USB Debugging is enabled.
2. On other versions of Android, there will be a Developer options button below System settings, which will have a USB debugging option:
Note: (On the latest versions, Google made a change that requires you to open up "About phone" and tap your "Build number" 7 times to get the "Developer options" to show up. This change was made to prevent non-developers from accidentally accessing complex settings.
1. On earlier versions of Android, you could find it by selecting Applications and then Development.
Check that USB Debugging is enabled.
2. On other versions of Android, there will be a Developer options button below System settings, which will have a USB debugging option:
Note: (On the latest versions, Google made a change that requires you to open up "About phone" and tap your "Build number" 7 times to get the "Developer options" to show up. This change was made to prevent non-developers from accidentally accessing complex settings.
2. Connect the device to the computer
Once you have enabled USB debugging, you should now connect your device to the computer. Now, open up your new Eclipse (or old version if you decided to use that) and run an application!
You should be able to see this screen (if not, click on the drop down arrow to the right of the Run button, click Run configurations, click on the Target Tab, and select the Radio button labeled Always prompt to pick device. Then try running again.).
You should be able to see this screen (if not, click on the drop down arrow to the right of the Run button, click Run configurations, click on the Target Tab, and select the Radio button labeled Always prompt to pick device. Then try running again.).
You can see that I am given the option of Choos(ing) a running Android device and Launch(ing) a new Android Virtual Device.
If I choose the former, the Application will deploy to my device (and this is reflected in the console as shown below).
If I choose the former, the Application will deploy to my device (and this is reflected in the console as shown below).
And sure enough, when I turn on my phone, the application will be running!
Examining the Android Application
Before we begin creating our game on Android, we must first discuss the various parts that come together to form an Android application. I will be providing multiple screenshots and describing what each section does. The information will not go into too much detail, as most of this information is learned by doing, not reading.
Project Folders |
The parts of an Android APp
src folder - just like in a Java project, this is where the code goes.
gen folder - this folder contains automatically generated code. You do not want to manually edit it. Inside it, the R.java file assigns a numerical value to each resource that you place into your project. It will work flawlessly (for the most part) without your involvement. Android 4.2, Android Dependencies, libs contain various libraries and dependencies required by the application. assets folder will contain various resources. The res folder can also contain resource such as strings, layouts, and images Usually, the res folder contains various versions of each of these resources so that your Android application will use different strings, layouts, and images depending on the language, screen size, and screen resolution, respectively. proguard refers to a tool that "shrinks, optimizes, and obfuscates" your code to make it harder to reverse engineer. It works automatically and will prevent MOST users from retrieving your full source code. |
Android manifest (AndroidManifest.xml)
The AndroidManifest.xml file is a very important one that contains a lot of information. In here, you can change the version number of your game, minimum SDK version, the MAIN activity (similar to a main method, the first activity, or page, that opens), and much more. We will be talking about this file in more depth throughout the tutorial.
If you double click on the AndroidManifest, you will see the following:
If you double click on the AndroidManifest, you will see the following:
The first four tabs make it very easy to change features. By filling out a few forms and pressing buttons, you can add permissions (described below), change version numbers (for patches), and etc. When you interact with the first four tabs, you are making changes to the AndroidManifest.xml file.
You can see the XML version of this file by selecting the tab labeled: AndroidManifest.xml.
You can see the XML version of this file by selecting the tab labeled: AndroidManifest.xml.
Here, you can see various information regarding your app all in one place.
permissions
An interesting feature on Android is that, by default, it prevents any application from making unwanted changes to the device. As such, it implements a system of Permissions. Every time that a user installs an App, Android will inform the user that the Application will require certain permissions (such as the ability to access your SD card, camera, or GPS). If the user denies these permissions, the application will not install.
These permissions, although most people ignore them completely, are very powerful. Potentially, you could lose all the files from your SD Card (if the creator of an Application were to add a few lines of code to their App), and have your address and information tracked.
Therefore, to maximize the number of downloads by earning the confidence of wary users, you should only ask for permissions that you absolutely need (such as wakelock, which prevents the phone from going to sleep). By doing this, you prevent yourself from making accidental changes to the user's device.
These permissions, although most people ignore them completely, are very powerful. Potentially, you could lose all the files from your SD Card (if the creator of an Application were to add a few lines of code to their App), and have your address and information tracked.
Therefore, to maximize the number of downloads by earning the confidence of wary users, you should only ask for permissions that you absolutely need (such as wakelock, which prevents the phone from going to sleep). By doing this, you prevent yourself from making accidental changes to the user's device.
That's all you will need to know for now regarding Android.
In Day 5, we will begin creating our framework, so that we can build our game on top of it.
Thank you so much for reading!
In Day 5, we will begin creating our framework, so that we can build our game on top of it.
Thank you so much for reading!
As always, feel free to email me questions at jamescho7@kilobolt.com
|
|

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