Created
October 18, 2010 05:51
-
-
Save galex/631791 to your computer and use it in GitHub Desktop.
android app blocks device from going into sleep/stand by mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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