Enable Hardware Acceleration in Your Android 3.0 Apps
Android 3.0 (Honeycomb) boasts a new, improved OpenGL rendering pipeline for common 2D graphics operations that Android developers can harness easily from within their applications. But what types of applications will benefit from this new feature? How is it used? What are some of the problems one might encounter?
Just about every application draws on the screen in some form or another. Whether you're using standard views or custom drawing, 2D hardware acceleration can improve your application under almost all circumstances. We'll talk more about some of the problematic situations in a moment.
How Do I Enable Android 3.0 Hardware Acceleration?
Enabling your application to take advantage of the hardware acceleration available on devices running Android 3.0+ can be as easy as setting a flag in your application Manifest file and updating your application and you can fine-tune your acceleration needs at the application, activity, window, or view level. This means that you'll need to recompile your application in order to take advantage of the acceleration features.
First, you'll want to enable acceleration within your application by way of the application manifest file. This is as simple as adding and enabling the new attribute called android:hardwareAccelerated within your application tag. If your app uses only standard views, then you're good to go. Most operations involving Camera, Canvas, ColorFilter, Paint, Shader, and Xfermode will be accelerated automatically.
How Do I Fine-Tune Android 3.0 Hardware Acceleration?
If you've got custom drawing operations or work with Canvas and Paints in your app, you should pay attention to what features are available in Android hardware acceleration at this time. Certain Canvas and Paint operations are not currently supported, while others behave differently depending using hardware versus software acceleration. Test your app thoroughly, and if you run into problems, you've got a couple of options:
- Work around the problem by re-implementing your drawing code using supported functionality.
- Turn off hardware acceleration on that activity, window, or specific view control, and rely upon the default software acceleration you were using prior.
Which Graphics Operations Does Android 3.0 Hardware Acceleration Support?
The Android documentation does not list the specific operations supported or not supported by Honeycomb's hardware acceleration improvements. Instead, it simply recommends testing your application thoroughly and modifying your app as necessary. However, Googler Romain Guy gives a helpful list of methods that fall into these two categories in this Android Developer's Blog post.
Page 1 of 2