Code example for PowerManager.WakeLock

Methods: acquire

0
            PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
            Log.d(TAG, "PowerManager acquired");
            wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKE_LOCK_TAG);
            Log.d(TAG, "WakeLock set");
        } 
        wakeLock.acquire();
        Log.d(TAG, "WakeLock acquired");
    } 
 
    private void stopWakeLock() { 
        if (wakeLock != null) {
            wakeLock.release();
            Log.d(TAG, "WakeLock released");
        } 
    } 
 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.torch_toggle);