Code example for PowerManager.WakeLock

Methods: acquire

                // It can take hundreds of ms flush the audio pipeline after 
                // apps pause audio playback, but audio route changes are 
                // immediate, so delay the route change by 1000ms. 
                // This could be improved once the audio sub-system provides an 
                // interface to clear the audio pipeline. 
                mHandler.sendEmptyMessageDelayed(0, 1000);
            } else { 
    private synchronized final void sendIntent(boolean isUnplug) {
        //  Pack up the values and broadcast them to everyone 
        Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);
        intent.putExtra("state", mHeadsetState);
        intent.putExtra("name", mHeadsetName);
Contextual code suggestions in your IDE  Get Codota for Java