O'Reilly logo

Programming Android by Zigurd Mednieks, G. Blake Meike, Masumi Nakamura, Laird Dornin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Life Cycle Methods of the Application Class

The life cycle methods of the Application class are, and should be, infrequently used in simple applications. And they should be used with restraint even in complex applications. Is is easy to bloat Application class overrides with data that hangs around in memory across multiple activities. This defeats Android’s ability to manage resources on a per-component basis. For example, if you move the reference to some data from an Activity object to the Application object, all you have done is extend the system’s chase for resources in a low-memory situation to the application life cycle, and you must manage this data separately from the activity life cycle.

Here, we implement the life cycle methods of the Application class to show their place in the Android application life cycle, and because logging information from these methods may be useful:

package com.finchframework.finch; import android.app.Application; import android.content.res.Configuration; import android.util.Log; /** * @author zigurd * * This the framework's Application subclass. This illustrates what * you may need to do in an Application subclass. * * To get this class instantiated, you must refer to it in the * application tag of the manifest. */ public class FinchApplication extends Application { private final String TAG = this.getClass().getSimpleName(); @Override public void onCreate() { // First, call the parent class super.onCreate(); // This is a good place to put code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required