Professional Documents
Culture Documents
Hour 3
Hour 3
Bhargava
November 7, 2010
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.
This example shows how to retrieve resources using the resource ID in the
R.java class.
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.