From 529318a713fc416b39fd67a4e6b6c8475ae16760 Mon Sep 17 00:00:00 2001
From: Charles Chen
After {@link Build.VERSION_CODES#R}, {@link Resources} must be obtained by + * {@link android.app.Activity} or {@link android.content.Context} created with + * {@link android.content.Context#createWindowContext(int, Bundle)}. + * {@link Application#getResources()} may report wrong values in multi-window or on secondary + * displays. + * *
For more information about using resources, see the documentation about Application Resources.
*/ @@ -2024,10 +2033,20 @@ public class Resources { } /** - * Return the current display metrics that are in effect for this resource - * object. The returned object should be treated as read-only. - * - * @return The resource's current display metrics. + * Return the current display metrics that are in effect for this resource + * object. The returned object should be treated as read-only. + * + *Note that the reported value may be different than the window this application is + * interested in.
+ * + *Best practices are to obtain metrics from {@link WindowManager#getCurrentWindowMetrics()} + * for window bounds, {@link Display#getRealMetrics(DisplayMetrics)} for display bounds and + * obtain density from {@link Configuration#densityDpi}. The value obtained from this API may be + * wrong if the {@link Resources} is from the context which is different than the window is + * attached such as {@link Application#getResources()}. + *
+ * + * @return The resource's current display metrics. */ public DisplayMetrics getDisplayMetrics() { return mResourcesImpl.getDisplayMetrics();