android.app
Class Application

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.app.Application
All Implemented Interfaces:
ComponentCallbacks, ComponentCallbacks2

public class Application
extends ContextWrapper
implements ComponentCallbacks2

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.


Nested Class Summary
static interface Application.ActivityLifecycleCallbacks
           
 
Field Summary
 LoadedApk mLoadedApk
           
 
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_WAIVE_PRIORITY, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, COUNTRY_DETECTOR, DEVICE_POLICY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SIP_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, THROTTLE_SERVICE, UI_MODE_SERVICE, USB_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Fields inherited from interface android.content.ComponentCallbacks2
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_UI_HIDDEN
 
Constructor Summary
Application()
           
 
Method Summary
 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.
 void onTrimMemory(int level)
          Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.
 void registerActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback)
           
 void registerComponentCallbacks(ComponentCallbacks callback)
          Add a new ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called.
 void unregisterActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback)
           
 void unregisterComponentCallbacks(ComponentCallbacks callback)
          Remove a ComponentCallbacks objec that was previously registered with Context.registerComponentCallbacks(ComponentCallbacks).
 
Methods inherited from class android.content.ContextWrapper
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPrefsFile, getSystemService, getTheme, getThemeResId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, sendStickyOrderedBroadcast, setTheme, setWallpaper, setWallpaper, startActivities, startActivity, startInstrumentation, startIntentSender, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mLoadedApk

public LoadedApk mLoadedApk
Constructor Detail

Application

public Application()
Method Detail

onCreate

public void onCreate()
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().


onTerminate

public void onTerminate()
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.


onConfigurationChanged

public void onConfigurationChanged(Configuration newConfig)
Description copied from interface: ComponentCallbacks
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.

Specified by:
onConfigurationChanged in interface ComponentCallbacks
Parameters:
newConfig - The new device configuration.

onLowMemory

public void onLowMemory()
Description copied from interface: ComponentCallbacks
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.

Specified by:
onLowMemory in interface ComponentCallbacks

onTrimMemory

public void onTrimMemory(int level)
Description copied from interface: ComponentCallbacks2
Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. This will happen for example when it goes in the background and there is not enough memory to keep as many background processes running as desired.

Specified by:
onTrimMemory in interface ComponentCallbacks2
Parameters:
level - The context of the trim, giving a hint of the amount of trimming the application may like to perform. May be ComponentCallbacks2.TRIM_MEMORY_COMPLETE, ComponentCallbacks2.TRIM_MEMORY_MODERATE, ComponentCallbacks2.TRIM_MEMORY_BACKGROUND, or ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN.

registerComponentCallbacks

public void registerComponentCallbacks(ComponentCallbacks callback)
Description copied from class: Context
Add a new ComponentCallbacks to the base application of the Context, which will be called at the same times as the ComponentCallbacks methods of activities and other components are called. Note that you must be sure to use Context.unregisterComponentCallbacks(android.content.ComponentCallbacks) when appropriate in the future; this will not be removed for you.

Overrides:
registerComponentCallbacks in class Context
Parameters:
callback - The interface to call. This can be either a ComponentCallbacks or ComponentCallbacks2 interface.

unregisterComponentCallbacks

public void unregisterComponentCallbacks(ComponentCallbacks callback)
Description copied from class: Context
Remove a ComponentCallbacks objec that was previously registered with Context.registerComponentCallbacks(ComponentCallbacks).

Overrides:
unregisterComponentCallbacks in class Context

registerActivityLifecycleCallbacks

public void registerActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback)

unregisterActivityLifecycleCallbacks

public void unregisterActivityLifecycleCallbacks(Application.ActivityLifecycleCallbacks callback)