• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.app;
18 
19 import android.content.ComponentCallbacks;
20 import android.content.Context;
21 import android.content.ContextWrapper;
22 import android.content.res.Configuration;
23 
24 /**
25  * Base class for those who need to maintain global application state. You can
26  * provide your own implementation by specifying its name in your
27  * AndroidManifest.xml's <application> tag, which will cause that class
28  * to be instantiated for you when the process for your application/package is
29  * created.
30  *
31  * <p class="note">There is normally no need to subclass Application.  In
32  * most situation, static singletons can provide the same functionality in a
33  * more modular way.  If your singleton needs a global context (for example
34  * to register broadcast receivers), the function to retrieve it can be
35  * given a {@link android.content.Context} which internally uses
36  * {@link android.content.Context#getApplicationContext() Context.getApplicationContext()}
37  * when first constructing the singleton.</p>
38  */
39 public class Application extends ContextWrapper implements ComponentCallbacks {
40 
Application()41     public Application() {
42         super(null);
43     }
44 
45     /**
46      * Called when the application is starting, before any other application
47      * objects have been created.  Implementations should be as quick as
48      * possible (for example using lazy initialization of state) since the time
49      * spent in this function directly impacts the performance of starting the
50      * first activity, service, or receiver in a process.
51      * If you override this method, be sure to call super.onCreate().
52      */
onCreate()53     public void onCreate() {
54     }
55 
56     /**
57      * This method is for use in emulated process environments.  It will
58      * never be called on a production Android device, where processes are
59      * removed by simply killing them; no user code (including this callback)
60      * is executed when doing so.
61      */
onTerminate()62     public void onTerminate() {
63     }
64 
onConfigurationChanged(Configuration newConfig)65     public void onConfigurationChanged(Configuration newConfig) {
66     }
67 
onLowMemory()68     public void onLowMemory() {
69     }
70 
71     // ------------------ Internal API ------------------
72 
73     /**
74      * @hide
75      */
attach(Context context)76     /* package */ final void attach(Context context) {
77         attachBaseContext(context);
78     }
79 
80 }
81