Added in API level 1

Application


open class Application : ContextWrapper, ComponentCallbacks2
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Application

Base class for maintaining global application state. You can provide your own implementation by creating a subclass and specifying the fully-qualified name of this subclass as the "android:name" attribute in your AndroidManifest.xml's <application> tag. The Application class, or your subclass of the Application class, is instantiated before any other class when the process for your application/package is created.

Note: There is normally no need to subclass Application. In most situations, 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), include Context.getApplicationContext() as a android.content.Context argument when invoking your singleton's getInstance() method.

Summary

Nested classes
abstract

abstract

Callback interface for use with Application#registerOnProvideAssistDataListener and Application#unregisterOnProvideAssistDataListener.

Inherited constants
Public constructors

Public methods
open static String!

Returns the name of the current process.

open Unit

Called by the system when the device configuration changes while your component is running.

open Unit

Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created.

open Unit

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage.

open Unit

This method is for use in emulated process environments.

open Unit
onTrimMemory(level: Int)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

open Unit

open Unit

open Unit

open Unit

open Unit

open Unit

Inherited functions

Public constructors

Application

Added in API level 1
Application()

Public methods

getProcessName

Added in API level 28
open static fun getProcessName(): String!

Returns the name of the current process. A package's default process name is the same as its package name. Non-default processes will look like "$PACKAGE_NAME:$NAME", where $NAME corresponds to an android:process attribute within AndroidManifest.xml.

onConfigurationChanged

Added in API level 1
open fun onConfigurationChanged(newConfig: Configuration): Unit

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.

For more information, read Handling Runtime Changes. If you override this method you must call through to the superclass implementation.

Parameters
newConfig Configuration: This value cannot be null.

onCreate

Added in API level 1
open fun onCreate(): Unit

Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) 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().

Be aware that direct boot may also affect callback order on Android android.os.Build.VERSION_CODES#N and later devices. Until the user unlocks the device, only direct boot aware components are allowed to run. You should consider that all direct boot unaware components, including such android.content.ContentProvider, are disabled until user unlock happens, especially when component callback order matters.


If you override this method you must call through to the superclass implementation.

onLowMemory

Added in API level 1
open fun onLowMemory(): Unit

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage. While the exact point at which this will be called is not defined, generally it will happen when 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. If you override this method you must call through to the superclass implementation.

onTerminate

Added in API level 1
open fun onTerminate(): Unit

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.
If you override this method you must call through to the superclass implementation.

onTrimMemory

Added in API level 14
open fun onTrimMemory(level: Int): Unit

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. You should never compare to exact values of the level, since new intermediate values may be added -- you will typically want to compare if the value is greater or equal to a level you are interested in.

To retrieve the processes current trim level at any point, you can use ActivityManager.getMyMemoryState(RunningAppProcessInfo). If you override this method you must call through to the superclass implementation.

Parameters
level Int: The context of the trim, giving a hint of the amount of trimming the application may like to perform. Value is android.content.ComponentCallbacks2#TRIM_MEMORY_COMPLETE, android.content.ComponentCallbacks2#TRIM_MEMORY_MODERATE, android.content.ComponentCallbacks2#TRIM_MEMORY_BACKGROUND, android.content.ComponentCallbacks2#TRIM_MEMORY_UI_HIDDEN, android.content.ComponentCallbacks2#TRIM_MEMORY_RUNNING_CRITICAL, android.content.ComponentCallbacks2#TRIM_MEMORY_RUNNING_LOW, or android.content.ComponentCallbacks2#TRIM_MEMORY_RUNNING_MODERATE

registerActivityLifecycleCallbacks

Added in API level 14
open fun registerActivityLifecycleCallbacks(callback: Application.ActivityLifecycleCallbacks!): Unit

registerComponentCallbacks

Added in API level 14
open fun registerComponentCallbacks(callback: ComponentCallbacks!): Unit
Parameters
callback ComponentCallbacks!: The interface to call. This can be either a ComponentCallbacks or ComponentCallbacks2 interface.
Exceptions
java.lang.IllegalStateException if this method calls before attachBaseContext(android.content.Context)

registerOnProvideAssistDataListener

Added in API level 18
open fun registerOnProvideAssistDataListener(callback: Application.OnProvideAssistDataListener!): Unit

unregisterActivityLifecycleCallbacks

Added in API level 14
open fun unregisterActivityLifecycleCallbacks(callback: Application.ActivityLifecycleCallbacks!): Unit

unregisterComponentCallbacks

Added in API level 14
open fun unregisterComponentCallbacks(callback: ComponentCallbacks!): Unit
Parameters
callback ComponentCallbacks!: The interface to call. This can be either a ComponentCallbacks or ComponentCallbacks2 interface.
Exceptions
java.lang.IllegalStateException if this method calls before attachBaseContext(android.content.Context)

unregisterOnProvideAssistDataListener

Added in API level 18
open fun unregisterOnProvideAssistDataListener(callback: Application.OnProvideAssistDataListener!): Unit