Monday, February 21, 2011

Subclass Application class for Android project

In order to handle several system events, like low memory, configuration change, you will need to subclass from Android Application class. Note that only creating a derived Application class and adding it into the project are not enough. You also need to update the project's manifest file to specify the derived class full name in Application node's name attribute, as shown below:

MyApplication sub class:
public class MyApplication extends Application {
public static final String MyAppTag = "MyAppTag";

@Override
public final void onCreate() {
Log.v(MyAppTag, "MyAppliation onCreate");
super.onCreate();
}
}

Updated AndroidManifest.xml:

android:label="@string/app_name"
android:name="MyApplication"
android:description="@string/app_desc"


Jonathan

No comments:

Post a Comment