Skip to content

Instantly share code, notes, and snippets.

@dezull
Created January 22, 2017 04:05
Show Gist options
  • Save dezull/4c2719f1f9140b4b4b9103e201c53eb3 to your computer and use it in GitHub Desktop.
Save dezull/4c2719f1f9140b4b4b9103e201c53eb3 to your computer and use it in GitHub Desktop.
public class DebugApplication extends Application {
private static final String TAG = DebugApplication.class.getSimpleName();
private static ActivityLifecycleCallbacks activityCallbacks = new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle bundle) { /* Don't care */ }
@Override
public void onActivityStarted(Activity activity) { /* Don't care */ }
@Override
public void onActivityResumed(Activity activity) {
PowerManager pm = (PowerManager) activity.getSystemService(POWER_SERVICE);
if (!pm.isScreenOn()) {
PowerManager.WakeLock wl = pm.newWakeLock(
PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
Log.d(TAG, "Wakey wakey [" + activity.getClass().getSimpleName() + "]");
wl.acquire();
wl.release();
}
}
@Override
public void onActivityPaused(Activity activity) { /* Don't care */ }
@Override
public void onActivityStopped(Activity activity) { /* Don't care */ }
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { /* Don't care */ }
@Override
public void onActivityDestroyed(Activity activity) { /* Don't care */ }
};
@Override
public void onCreate() {
super.onCreate();
this.registerActivityLifecycleCallbacks(activityCallbacks);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment