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