Setting android:hardwareAccelerated="true" in <activity> or in <application>

Ser*_*vic 8 android hardware-acceleration android-manifest

I want my app, which relies heavily on GPU, to use hardware acceleration. On some forums I've been suggested to set android:hardwareAccelerated="true" inside <application> and on other forums same attribute inside <activity> inside my AndroidManifest.xml. Below is the representation of what it looks like:

<application
    ...
    android:hardwareAccelerated="true"
    ...>
    <activity
        ...
        android:hardwareAccelerated="true"
        ...>
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

I ended up setting in both, yet I wonder, which one is the right way, and what is the difference?

Ale*_*x.F 14

默认情况下,硬件加速是启用的,因此除非需要将其禁用,否则不必进行设置。如文档中所述:

如果您的目标API级别> = 14,则默认情况下启用硬件加速,但也可以显式启用。

回答您的问题。将其设置在Application标签上会影响整个应用程序,而将其设置在Activity标签上会影响该活动。

应用等级

在您的Android清单文件中,将以下属性添加到标记中,以为整个应用程序启用硬件加速:

<application android:hardwareAccelerated="true" ...>
Run Code Online (Sandbox Code Playgroud)

活动水平

如果在全局启用硬件加速的情况下应用程序无法正常运行,则也可以针对单个活动对其进行控制。要在活动级别启用或禁用硬件加速,可以为元素使用android:hardwareAccelerated属性。下面的示例为整个应用程序启用硬件加速,但对一项活动禁用它:

<application android:hardwareAccelerated="true">
    <activity ... />
    <activity android:hardwareAccelerated="false" />
</application>
Run Code Online (Sandbox Code Playgroud)