Game Development Reference
In-Depth Information
We can easily add new source files, folders, and other resources in the Package Explorer view by
right-clicking the folder in which we want to put the new resources and selecting New plus the
corresponding resource type we want to create. For now, though, we'll leave everything as is.
Next, let's look into modifying our basic application setup and configuration so it is compatible
with as many Android versions and devices as possible.
Making the Application Compatible with All Android Versions
Previously we created a project specifying Android 1.5 as our minimum SDK. Sadly, the ADT
plug-in has a minor bug where it forgets to create the folder that houses the icon image for our
application on Android 1.5. Here's how we fix that:
Create a folder in the res/ directory called drawable/ . You can do this
directly in the Package Explorer view by right-clicking the res/ directory
and chose New ➤ Folder from the context menu.
1.
Copy the ic_launcher.png file from the res/drawable-mdpi/ folder to
the new assets/drawable/ folder. This folder is required for Android 1.5,
whereas higher versions look for icons and other application resources
in the other folders, based on their screen size and resolution. We'll talk
about this in Chapter 4.
2.
With these changes, your application can run on all the Android versions that are currently out in
the wild!
Writing the Application Code
We still haven't written a single line of code, so let's change that. The Android project wizard
created a template activity class for us called HelloWorldActivity , which will get displayed
when we run the application on the emulator or a device. Open the source of the class by
double-clicking the file in the Package Explorer view. We'll replace that template code with the
code in Listing 2-1.
Listing 2-1. HelloWorldActivity.java
package com.helloworld;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class HelloWorldActivity extends Activity
implements View.OnClickListener {
Button button;
int touchCount;
 
Search WWH ::




Custom Search