Skip to content

Instantly share code, notes, and snippets.

@galex
Created October 18, 2010 05:51
Show Gist options
  • Save galex/631791 to your computer and use it in GitHub Desktop.
Save galex/631791 to your computer and use it in GitHub Desktop.
android app blocks device from going into sleep/stand by mode
public class MyActivity extends Activity {
// define the wakeLock as attribute
PowerManager.WakeLock wakeLock ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "tag");
wakeLock.acquire();
}
@Override
protected void onDestroy() {
super.onDestroy();
wakeLock.release();
}
@Override
public void onResume() {
super.onResume();
wakeLock.acquire();
}
@Override
public void onPause() {
super.onResume();
wakeLock.release();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment