Java tutorial
//package com.java2s; import java.lang.ref.WeakReference; import java.lang.reflect.Method; import android.graphics.Canvas; public class Main { public static final boolean IS_HARDWARE_ACCELERATED_FAST_CALL = true; private static Method methodIsHardwareAccelerated; private static WeakReference<Canvas> sLastCanvas; private static boolean sLastCanvasIsHardwareAccelerated; static public boolean isHardwareAccelerated(Canvas canvas) { // Return cached value, faster than use reflection if (sLastCanvas != null && sLastCanvas.get() == canvas) { return sLastCanvasIsHardwareAccelerated; } sLastCanvasIsHardwareAccelerated = false; if (methodIsHardwareAccelerated != null) { try { Object result = methodIsHardwareAccelerated.invoke(canvas); sLastCanvasIsHardwareAccelerated = (Boolean) result; } catch (Throwable t) { } } if (IS_HARDWARE_ACCELERATED_FAST_CALL) sLastCanvas = new WeakReference<Canvas>(canvas); return sLastCanvasIsHardwareAccelerated; } }