24

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?

2
  • Better use it in lower resolution (view) and not for whole application.
    – RonTLV
    Aug 30, 2018 at 7:57
  • @RonTLV why you think it's better? Aug 13, 2019 at 17:45

2 Answers 2

40

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>
4

If you set on <application> it means that the whole app has the hardwareAccelerated feature and you don't need to set it again on <activity>, but if your application does not behave properly with hardware acceleration turned on globally, you can set it on <activity>, and it means only that specific activity has the feature hardwareAccelerated and not the whole app. So I think on your case, you can set it only on <application> tag.

See more here. https://developer.android.com/guide/topics/graphics/hardware-accel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.