Hardware acceleration is available with Android 3.0 (API level 11).
As of Android 4.0 (API level 14) it is enabled by default.
Hardware acceleration can be controlled at the following levels:
-
Application
In AndroidManifest.xml, indicating true
or false
to the android:hardwareAccelerated
attribute, in the <application/>
section:
<application android:hardwareAccelerated="true" ...>
-
Activity
In AndroidManifest.xml, indicating true
or false
to the android:hardwareAccelerated
attribute, in the <activity/>
section:
<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />
</application>
-
Window
Using% Window% method to enable hardware acceleration:
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
At this level it is not possible to disable hardware acceleration.
-
View
Using the% View method to disable hardware acceleration:
myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
At this level it is not possible to enable hardware acceleration.
There are two ways to know if an application is hardware accelerated:
Note that before using the method you must be sure that View is associated with a Window , which is not the case for example onCreate ( ).
One place where you have this guarantee is onWindowFocusChanged () Activity.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
boolean isAccelerated = view.isHardwareAccelerated();
}
}
For more detailed information see Hardware Acceleration in the documentation.