I am building an app that requires a lot of drawing on the canvas. I notice that the app is a bit laggy in devices with high resolution (nexus 7 for example). I saw there is a Force GPU option in the developer option. When Force GPU is enabled, my app runs absolutely smooth.
I have read that this Force GPU option is called Hardware Acceleration and it is available only for Android 3.0 and above.
My app is targeting Android 2.3 and above.
Is it possible to programmatically enable Hardware Accelerated (or Force GPU--whatever the magic is called) on any Android 3.0 or above devices?
Something like:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
Turn On Hardware Accelerate HERE but How can i do this?
any code snippet would be welcome/helpful/thanks
}
Tap on Build number 7 times until you get a message saying “You are now a developer“. Go back to Settings, scroll down and you should be able to see a new option called Developer options. Tap on it. Scroll down to the Hardware accelerated rendering and enable the toggle next to Force GPU rendering.
On your device, go to Settings and tap Developer Options. In the Monitoring section, select Profile GPU Rendering or Profile HWUI rendering, depending on the version of Android running on the device. In the Profile GPU Rendering dialog, choose On screen as bars to overlay the graphs on the screen of your device.
On certain devices, GPU consumes more power the CPU, hence you may observe 5-15% lower battery life with option enabled. I would recommend having this option enabled on devices with weaker CPUs e.g. You should seldom need to enable this on dual-core 1.4ghz ARM CPU.
Turning off HW overlays is a setting that can be used to increase performance on some games. Disabling this setting may cause some games to crash or not work properly. It will also reduce the battery life of your device because it forces the GPU to render graphics at a higher resolution than necessary.
I assume you've already added android:hardwareAccelerated to your Manifest file?
<application android:hardwareAccelerated="true" ...>
That is what enables hardware acceleration within your application per the guide on hardware acceleration and should do exactly what forcing GPU does at a system level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With