Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Building android applications

Bhargava
November 7, 2010

1 Designing typical android application


The 3 most important classes on the android platform are Context, Activity and
Intent. An android application is a collection of tasks, each of which is called
an activity. Each activity has its own purpose and UI.

1.1 Example: A game application Chippy’s Revenge


There are 5 screens in this application. And each of the screens is handled by a
separate activity.
• Splash: This just displays the splash and then displays the menu. The
purpose of this activity is to start the menu activity.
• Menu: This activity displays the menu and according to the button pressed
it starts a new activity.
• Play: This activity is responsible for playing the game.
• Scores: This activity is activated when the user uses the menu and selects
the score button. The purpose of this activity is to show the high scores.
• Help: This activity is responsible for displaying the instructions on how
to play the game, controls and other stuff.
The main point to note is that each activity has its own UI defined in a
separate layout resource file.

2 Application context
This is the interface to the global information about the application. We use
a context to load and use the application resources. It is an abstract class and
hence can never be used directly. We need to use objects of its child class such
as activity, service etc.
The application context for the current process can be obtained by using
Context context = getApplicationContext();

1
With this we can now access the application-wide services (The book does
a poor job here, look further in the text and see if you can come
up with some example ). Most of the methods declared in the Context
class are abstract and many of these methods, for example getResources(),
getApplicationContext(), are defined by the class ContextWrapper.

• Retrieving application resources: Application resources can be retrieved


by using, for example,

String aString = getResources().getString(R.string.hello);

This example shows how to retrieve resources using the resource ID in the
R.java class.

• Accessing application preferences: We can retrieve the application prefer-


ences using getSharedPreferences() method of the application context.

3 Activities
The Activity class is central to all android applications. For each screen we
implement an activity. The user moves from one activity to another over the
course of playing game.

3.1 How to launch Activities


• Designating a launch activity in the manifest file.

• Launching an activity using the application context.

• Launching a child activity from a parent activity.

You might also like