From 314ba598eedcf0848e3ab6ff1d5a277f18cb5d8a Mon Sep 17 00:00:00 2001 From: An An Yu Date: Mon, 29 Nov 2021 21:31:02 -0800 Subject: [PATCH] Add documentation on DisplayContext API that returned Resources could be stale. Test: None Bug: 165859619 Change-Id: I0fb642c310ac33a4a79bff94683864d1fc80824a --- core/java/android/content/Context.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java index ce2efcf4ac7f5..afa6d1301f66a 100644 --- a/core/java/android/content/Context.java +++ b/core/java/android/content/Context.java @@ -6653,21 +6653,27 @@ public abstract class Context { @NonNull Configuration overrideConfiguration); /** - * Returns a new Context object from the current context but with resources - * adjusted to match the metrics of display. Each call to this method + * Returns a new {@code Context} object from the current context but with resources + * adjusted to match the metrics of {@code display}. Each call to this method * returns a new instance of a context object. Context objects are not shared; however, * common state (such as the {@link ClassLoader} and other resources for the same - * configuration) can be shared, so the Context itself is lightweight. + * configuration) can be shared, so the {@code Context} itself is lightweight. + * + *

Note: + * This {@code Context} is not expected to be updated with new configuration if the + * underlying display configuration changes and the cached {@code Resources} it returns + * could be stale. It is suggested to use + * {@link android.hardware.display.DisplayManager.DisplayListener} to listen for + * changes and re-create an instance if necessary.

*

+ * This {@code Context} is not a UI context, do not use it to access UI components + * or obtain a {@link WindowManager} instance. + *

* To obtain an instance of {@link WindowManager} configured to show windows on the given * display, call {@link #createWindowContext(int, Bundle)} on the returned display context, * then call {@link #getSystemService(String)} or {@link #getSystemService(Class)} on the * returned window context. - *

- * Note: The context returned by createDisplayContext(Display) is not a UI - * context. Do not access UI components or obtain a {@link WindowManager} from the context - * created by createDisplayContext(Display). - * + *

* @param display The display to which the current context's resources are adjusted. * * @return A context for the display.