处理运行时屏幕分辨率更改

Handle runtime screen resolution changes

在一些新的 Android 7.0 固件中,有一个选项可以更改屏幕分辨率(例如 Android S7 Edge 的 7.0 固件可以选择在运行时从 qhd / fhd / hd 切换显示分辨率)。

我的调试尝试表明没有配置更改(因为我的应用正确处理了语言更改,但没有处理分辨率更改)。

如何正确处理这种配置更改?

根据 Screen Zoom documentation:

  • If an app targets API level 23 or lower, the system automatically kills all its background processes. This means that if a user switches away from such an app to open the Settings screen and changes the Display size setting, the system kills the app in the same manner that it would in a low-memory situation. If the app has any foreground processes, the system notifies those processes of the configuration change as described in Handling Runtime Changes, just as if the device's orientation had changed.

  • If an app targets Android 7.0, all of its processes (foreground and background) are notified of the configuration change as described in Handling Runtime Changes.

handling configuration changes for multi-window 类似,您应该确保处理以下 configChanges

android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"

我发现需要在 configChanges 中为 Android 7 中的 activity 设置一个未记录的标志 density 才能在屏幕缩放中存活.

android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|fontScale|density"