• 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.content;
18 
19 import android.annotation.NonNull;
20 import android.content.res.Configuration;
21 
22 /**
23  * The set of callback APIs that are common to all application components
24  * ({@link android.app.Activity}, {@link android.app.Service},
25  * {@link ContentProvider}, and {@link android.app.Application}).
26  *
27  * <p class="note"><strong>Note:</strong> You should also implement the {@link
28  * ComponentCallbacks2} interface, which provides the {@link
29  * ComponentCallbacks2#onTrimMemory} callback to help your app manage its memory usage more
30  * effectively.</p>
31  */
32 public interface ComponentCallbacks {
33     /**
34      * Called by the system when the device configuration changes while your
35      * component is running.  Note that, unlike activities, other components
36      * are never restarted when a configuration changes: they must always deal
37      * with the results of the change, such as by re-retrieving resources.
38      *
39      * <p>At the time that this function has been called, your Resources
40      * object will have been updated to return resource values matching the
41      * new configuration.
42      *
43      * <p>For more information, read <a href="{@docRoot}guide/topics/resources/runtime-changes.html"
44      * >Handling Runtime Changes</a>.
45      *
46      * @param newConfig The new device configuration.
47      */
onConfigurationChanged(@onNull Configuration newConfig)48     void onConfigurationChanged(@NonNull Configuration newConfig);
49 
50     /**
51      * This is called when the overall system is running low on memory, and
52      * actively running processes should trim their memory usage.  While
53      * the exact point at which this will be called is not defined, generally
54      * it will happen when all background process have been killed.
55      * That is, before reaching the point of killing processes hosting
56      * service and foreground UI that we would like to avoid killing.
57      *
58      * <p>You should implement this method to release
59      * any caches or other unnecessary resources you may be holding on to.
60      * The system will perform a garbage collection for you after returning from this method.
61      * <p>Preferably, you should implement {@link ComponentCallbacks2#onTrimMemory} from
62      * {@link ComponentCallbacks2} to incrementally unload your resources based on various
63      * levels of memory demands.  That API is available for API level 14 and higher, so you should
64      * only use this {@link #onLowMemory} method as a fallback for older versions, which can be
65      * treated the same as {@link ComponentCallbacks2#onTrimMemory} with the {@link
66      * ComponentCallbacks2#TRIM_MEMORY_COMPLETE} level.</p>
67      */
onLowMemory()68     void onLowMemory();
69 }
70