Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting different resource values using values folder for different API versions

I have been noticing a crash on Android 6 with error message - "A/OpenGLRenderer: Error: Ambient Vertex Buffer overflow!!!" Setting hardware accelerated to false for an activity in manifest file solves the problem, but affects the performance of the app (results into slower app).

I want to just set the value to false only if android version is 23 (android M) and not otherwise. Here is how I approached it:

Android Manifest file:

<activity
android:name=".MainActivity"
android:hardwareAccelerated="@bool/hardwareAcceleratedValue">

res/values/bool.xml

<resources>
    <bool name="hardwareAcceleratedValue">true</bool>
</resources>

res/values-v23/bool.xml

<resources>
    <bool name="hardwareAcceleratedValue">false</bool>
</resources>

With this, I was noticing slower performance on Android M devices (which was expected), but also on devices with Android 9. So I went ahead and created another folder for android 9 and added the file to it with "hardwareAcceleratedValue" as true and the performance was faster.

Question -

For android API's other than v23, shouldn't android read the "hardwareAcceleratedValue" value from res/values/bool.xml? Or will I have to create separate folders for every android API and create a bool.xml file within it i.e. res/values-v28/bool.xml or res/values-v27/bool.xml?

How can I just set "hardwareAcceleratedValue" to false only for Android-M or less and true for all versions beyond android-M?

like image 731
tech_human Avatar asked Jun 16 '26 04:06

tech_human


1 Answers

For android API's other than v23, shouldn't android read the "hardwareAcceleratedValue" value from res/values/bool.xml?

-v23 is used for API Level 23 and higher.

How can I just set "hardwareAcceleratedValue" to false only for Android-M or less and true for all versions beyond android-M?

Have false in res/values/bool.xml and true in res/values-v22/bool.xml. Android M is API Level 21, so -v22 will be used for all higher versions.

If by "android-M" you mean Android 5.x, then have false in res/values/bool.xml and true in res/values-v23/bool.xml, as Android 5.1 was API Level 22.

like image 73
CommonsWare Avatar answered Jun 18 '26 21:06

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!