public class

Application

extends ContextWrapper
implements ComponentCallbacks
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Application
Known Direct Subclasses

Class Overview

Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's <application> tag, which will cause that class to be instantiated for you when the process for your application/package is created.

There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton.

Summary

[Expand]
Inherited Constants
From class android.content.Context
Public Constructors
Application()
Public Methods
void onConfigurationChanged(Configuration newConfig)
Called by the system when the device configuration changes while your component is running.
void onCreate()
Called when the application is starting, before any other application objects have been created.
void onLowMemory()
This is called when the overall system is running low on memory, and would like actively running process to try to tighten their belt.
void onTerminate()
This method is for use in emulated process environments.
[Expand]
Inherited Methods
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks

Public Constructors

public Application ()

Since: API Level 1

Public Methods

public void onConfigurationChanged (Configuration newConfig)

Since: API Level 1

Called by the system when the device configuration changes while your component is running. Note that, unlike activities, other components are never restarted when a configuration changes: they must always deal with the results of the change, such as by re-retrieving resources.

At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.

Parameters
newConfig The new device configuration.

public void onCreate ()

Since: API Level 1

Called when the application is starting, before any other application objects have been created. Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process. If you override this method, be sure to call super.onCreate().

public void onLowMemory ()

Since: API Level 1

This is called when the overall system is running low on memory, and would like actively running process to try to tighten their belt. While the exact point at which this will be called is not defined, generally it will happen around the time all background process have been killed, that is before reaching the point of killing processes hosting service and foreground UI that we would like to avoid killing.

Applications that want to be nice can implement this method to release any caches or other unnecessary resources they may be holding on to. The system will perform a gc for you after returning from this method.

public void onTerminate ()

Since: API Level 1

This method is for use in emulated process environments. It will never be called on a production Android device, where processes are removed by simply killing them; no user code (including this callback) is executed when doing so.