FileDocCategorySizeDatePackage
Application.javaAPI DocAndroid 5.1 API10577Thu Mar 12 22:22:10 GMT 2015android.app

Application

public class Application extends android.content.ContextWrapper implements android.content.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 {@link android.content.Context} which internally uses {@link android.content.Context#getApplicationContext() Context.getApplicationContext()} when first constructing the singleton.

Fields Summary
private ArrayList
mComponentCallbacks
private ArrayList
mActivityLifecycleCallbacks
private ArrayList
mAssistCallbacks
public LoadedApk
mLoadedApk
Constructors Summary
public Application()


       
            
          
          
          
          
            
          
    

                   
       
                                                                     
             
    

      
        super(null);
    
Methods Summary
final voidattach(android.content.Context context)

hide

        attachBaseContext(context);
        mLoadedApk = ContextImpl.getImpl(context).mPackageInfo;
    
private java.lang.Object[]collectActivityLifecycleCallbacks()

        Object[] callbacks = null;
        synchronized (mActivityLifecycleCallbacks) {
            if (mActivityLifecycleCallbacks.size() > 0) {
                callbacks = mActivityLifecycleCallbacks.toArray();
            }
        }
        return callbacks;
    
private java.lang.Object[]collectComponentCallbacks()

        Object[] callbacks = null;
        synchronized (mComponentCallbacks) {
            if (mComponentCallbacks.size() > 0) {
                callbacks = mComponentCallbacks.toArray();
            }
        }
        return callbacks;
    
voiddispatchActivityCreated(Activity activity, android.os.Bundle savedInstanceState)

        Object[] callbacks = collectActivityLifecycleCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ActivityLifecycleCallbacks)callbacks[i]).onActivityCreated(activity,
                        savedInstanceState);
            }
        }
    
voiddispatchActivityDestroyed(Activity activity)

        Object[] callbacks = collectActivityLifecycleCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ActivityLifecycleCallbacks)callbacks[i]).onActivityDestroyed(activity);
            }
        }
    
voiddispatchActivityPaused(Activity activity)

        Object[] callbacks = collectActivityLifecycleCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ActivityLifecycleCallbacks)callbacks[i]).onActivityPaused(activity);
            }
        }
    
voiddispatchActivityResumed(Activity activity)

        Object[] callbacks = collectActivityLifecycleCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ActivityLifecycleCallbacks)callbacks[i]).onActivityResumed(activity);
            }
        }
    
voiddispatchActivitySaveInstanceState(Activity activity, android.os.Bundle outState)

        Object[] callbacks = collectActivityLifecycleCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ActivityLifecycleCallbacks)callbacks[i]).onActivitySaveInstanceState(activity,
                        outState);
            }
        }
    
voiddispatchActivityStarted(Activity activity)

        Object[] callbacks = collectActivityLifecycleCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ActivityLifecycleCallbacks)callbacks[i]).onActivityStarted(activity);
            }
        }
    
voiddispatchActivityStopped(Activity activity)

        Object[] callbacks = collectActivityLifecycleCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ActivityLifecycleCallbacks)callbacks[i]).onActivityStopped(activity);
            }
        }
    
voiddispatchOnProvideAssistData(Activity activity, android.os.Bundle data)

        Object[] callbacks;
        synchronized (this) {
            if (mAssistCallbacks == null) {
                return;
            }
            callbacks = mAssistCallbacks.toArray();
        }
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((OnProvideAssistDataListener)callbacks[i]).onProvideAssistData(activity, data);
            }
        }
    
public voidonConfigurationChanged(android.content.res.Configuration newConfig)

        Object[] callbacks = collectComponentCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ComponentCallbacks)callbacks[i]).onConfigurationChanged(newConfig);
            }
        }
    
public voidonCreate()
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().

    
public voidonLowMemory()

        Object[] callbacks = collectComponentCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                ((ComponentCallbacks)callbacks[i]).onLowMemory();
            }
        }
    
public voidonTerminate()
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.

    
public voidonTrimMemory(int level)

        Object[] callbacks = collectComponentCallbacks();
        if (callbacks != null) {
            for (int i=0; i<callbacks.length; i++) {
                Object c = callbacks[i];
                if (c instanceof ComponentCallbacks2) {
                    ((ComponentCallbacks2)c).onTrimMemory(level);
                }
            }
        }
    
public voidregisterActivityLifecycleCallbacks(android.app.Application$ActivityLifecycleCallbacks callback)

        synchronized (mActivityLifecycleCallbacks) {
            mActivityLifecycleCallbacks.add(callback);
        }
    
public voidregisterComponentCallbacks(android.content.ComponentCallbacks callback)

        synchronized (mComponentCallbacks) {
            mComponentCallbacks.add(callback);
        }
    
public voidregisterOnProvideAssistDataListener(android.app.Application$OnProvideAssistDataListener callback)

        synchronized (this) {
            if (mAssistCallbacks == null) {
                mAssistCallbacks = new ArrayList<OnProvideAssistDataListener>();
            }
            mAssistCallbacks.add(callback);
        }
    
public voidunregisterActivityLifecycleCallbacks(android.app.Application$ActivityLifecycleCallbacks callback)

        synchronized (mActivityLifecycleCallbacks) {
            mActivityLifecycleCallbacks.remove(callback);
        }
    
public voidunregisterComponentCallbacks(android.content.ComponentCallbacks callback)

        synchronized (mComponentCallbacks) {
            mComponentCallbacks.remove(callback);
        }
    
public voidunregisterOnProvideAssistDataListener(android.app.Application$OnProvideAssistDataListener callback)

        synchronized (this) {
            if (mAssistCallbacks != null) {
                mAssistCallbacks.remove(callback);
            }
        }