Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>

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

like image 949
Sergei Emelianov Avatar asked Aug 30 '18 07:08

Sergei Emelianov


1 Answers

Hardware acceleration is enabled by default so you don't have to set it unless you need to disable it. As said in the documentation:

Hardware acceleration is enabled by default if your Target API level is >=14, but can also be explicitly enabled.

To answer your question. Setting it on Application tag affects your whole application and setting it on Activity tag affects that activity.

Application level

In your Android manifest file, add the following attribute to the tag to enable hardware acceleration for your entire application:

<application android:hardwareAccelerated="true" ...>

Activity level

If your application does not behave properly with hardware acceleration turned on globally, you can control it for individual activities as well. To enable or disable hardware acceleration at the activity level, you can use the android:hardwareAccelerated attribute for the element. The following example enables hardware acceleration for the entire application but disables it for one activity:

<application android:hardwareAccelerated="true">
    <activity ... />
    <activity android:hardwareAccelerated="false" />
</application>
like image 194
Alex.F Avatar answered Oct 05 '22 10:10

Alex.F