With each release, specific Android APIs may become obsolete or need to be refactored to provide a better developer experience or support new platform capabilities. In these cases, Android will officially deprecate the obsolete APIs and direct developers to new APIs to use instead.
Deprecation means that we’ve ended official support for the APIs, but they will continue to remain available to developers. This page highlights some of the deprecations in this release of Android. To see other deprecations, refer to the API diff report.
RenderScript
Starting with Android 12, the RenderScript APIs are deprecated. They will continue to function, but we expect that device and component manufacturers will stop providing hardware acceleration support over time. To take full advantage of GPU acceleration, we recommend migrating away from RenderScript.
Android playlists
Android playlists are deprecated. The API is no longer maintained but the current functionality remains for compatibility.
We recommend reading and saving playlists as m3u files.
Display API deprecations
Android devices are becoming available in many different form factors, such as
large screens, tablets, and foldables. In order to render content appropriately
for each device, your app needs to determine the screen or display size. Over
time Android provided different APIs for retrieving this information. In
Android 11 we introduced the
WindowMetrics
API and deprecated
these methods:
In Android 12 we continue to recommend using WindowMetrics
and are deprecating these methods:
Apps should use the WindowMetrics
APIs to query the bounds of their window, or
Configuration.densityDpi
to query the current density.
Note that the Jetpack WindowManager
library includes a WindowMetrics
class that supports Android 4.0.1 (API level 14) and higher.
Examples
Here are some examples how to use WindowMetrics
.
First, be sure your app can make its activities fully resizable.
An activity should rely upon WindowMetrics
from an activity context for
any UI-related work, particularly
WindowManager.getCurrentWindowMetrics()
.
If your app creates a MediaProjection
, the bounds must be correctly sized
since the projection captures the display. If the app is fully resizable, the
activity context returns the correct bounds.
Kotlin
val projectionMetrics = activityContext .getSystemService(WindowManager::class.java).maximumWindowMetrics
Java
WindowMetrics projectionMetrics = activityContext .getSystemService(WindowManager.class).getMaximumWindowMetrics();
If the app is not fully resizable, it must query the bounds from a
WindowContext
instance, and retrieve the WindowMetrics of the maximum display
area available to the application using
WindowManager.getMaximumWindowMetrics()
Kotlin
val windowContext = context.createWindowContext(mContext.display!!, WindowManager.LayoutParams.TYPE_APPLICATION, null) val projectionMetrics = windowContext.getSystemService(WindowManager::class.java) .maximumWindowMetrics
Java
Context windowContext = mContext.createWindowContext(mContext.getDisplay(), WindowManager.LayoutParams.TYPE_APPLICATION, null; WindowMetrics projectionMetrics = windowContext.getWindowManager() .getMaximumWindowMetrics();