Android Q behavior changes: apps targeting Q

The Android Q platform includes behavior changes that may affect your app. The following behavior changes apply exclusively to apps that are targeting Android Q or higher. If your app sets targetSdkVersion to "android-Q" or higher, you should modify your app to support these behaviors properly, where applicable.

Make sure to also review the list of behavior changes that affect all apps running on Android Q.

Updates to non-SDK interface restrictions

To help ensure app stability and compatibility, the platform started restricting which non-SDK interfaces your app can use in Android 9 (API level 28). Android Q includes updated lists of restricted non-SDK interfaces based on collaboration with Android developers and the latest internal testing. Our goal is to make sure that public alternatives are available before we restrict non-SDK interfaces.

If you will not be targeting Android Q, some of these changes might not immediately affect you. However, while you can currently use non-SDK interfaces that are part of the greylist (depending on your app's target API level), using any non-SDK method or field always carries a high risk of breaking your app.

If you are unsure if your app uses non-SDK interfaces, you can test your app to find out. If your app relies on non-SDK interfaces, you should begin planning a migration to SDK alternatives. Nevertheless, we understand that some apps have valid use cases for using non-SDK interfaces. If you cannot find an alternative to using a non-SDK interface for a feature in your app, you should request a new public API.

To learn more, see Updates to non-SDK interface restrictions in Android Q and see Restrictions on non-SDK interfaces.

Shared memory

Ashmem has changed the format of dalvik maps in /proc/<pid>/maps, affecting apps that directly parse the maps file. Application developers should test the new /proc/<pid>/maps format on devices and parse accordingly if the app depends on dalvik map formats.

Apps targeting Q can no longer directly use ashmem (/dev/ashmem) and must instead access shared memory via the NDK’s ASharedMemory class. In addition, apps cannot make direct IOCTLs to existing ashmem file descriptors and must instead use either the NDK’s ASharedMemory class or the Android Java APIs for creating shared memory regions. This change increases security and robustness when working with shared memory, improving performance and security of Android overall.

Android runtime only accepts system-generated OAT files

The Android runtime (ART) no longer invokes dex2oat from the application process. This change means that the ART will only accept OAT files that the system has generated.

Enforcing AOT correctness in ART

In the past, the ahead-of-time (AOT) compilation performed by the Android Runtime (ART) could cause runtime crashes if the classpath environment was not the same at compile time and runtime. Android Q now always requires these environment contexts to be the same, resulting in the following changes in behavior:

  • Custom class loaders--that is, class loaders written by apps, unlike class loaders from the dalvik.system package--are not AOT-compiled. This is because ART cannot know about customized class lookup implementation at runtime.
  • Secondary dex files--that is, the dex files loaded manually by apps not in the primary APK--are now AOT-compiled in the background, as first-use compilation might be too expensive, leading to unwanted latency before execution. Note that for apps, adopting splits and moving away from secondary dex files is recommended.
  • Shared libraries in Android (the entries <library> and <uses-library> in an Android manifest) are now implemented with a new class loader hierarchy.

Permissions changes for fullscreen intents

Apps that target Android Q or higher and use notifications with fullscreen intents must request the USE_FULL_SCREEN_INTENT permission in their app's manifest file. This is a normal permission, so the system automatically grants it to the requesting app.

If an app that targets Android Q or higher attempts to create a notification with a fullscreen intent without requesting the USE_FULL_SCREEN_INTENT permission, the system ignores the fullscreen intent and outputs the following log message: Package [pkg]: Use of fullScreenIntent requires the USE_FULL_SCREEN_INTENT permission

Support for foldables

Android Q has changes that support foldables and large screen devices.

When an app runs on Android Q, the onResume() and onPause() methods work differently. When multiple apps appear at the same time in multi-window or multi-display mode, all the focusable top activities in visible stacks are in the resumed state, but only one of them, the "topmost resumed" activity, actually has focus. When running on versions earlier than Android Q, only a single activity in the system can be resumed at a time, all other visible activities are paused.

Do not confuse "focus" with the "topmost resumed" activity. The system assigns priorities to activities based on z-order to give higher priority to the activities that the user interacted with last. An activity can be top-resumed, but not have focus (for example, if the notification shade is expanded).

In Android Q, you can subscribe to the onTopResumedActivityChanged() callback to be notified when your activity acquires or loses the topmost resumed position. This is the equivalent of the resumed state before Q and can be useful as a hint if your app is using exclusive or singleton resources that might need to be shared with other apps.

The behavior of the resizeableActivity manifest attribute has also changed. If an app sets resizeableActivity=false in Android Q, it might be put in compatibility mode when the available screen size changes, or if the app moves from one screen to another.

Apps can use a new android:minAspectRatio attribute to indicate whether or not your app supports the new screen ratios.

Starting with version 3.5, Android Studio's emulator tool includes 7.3" and 8" virtual devices for testing your code with the Android Q system image.

For more information, see Building apps for Foldables.