From 4c157f450983f44e42edcb4cdcb7a57a301c19b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Sun, 3 Feb 2019 16:17:15 +0100 Subject: [PATCH] Some more improvements to fix #325 --- src/android/BackgroundExt.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/android/BackgroundExt.java b/src/android/BackgroundExt.java index 9f27859..4c34a46 100644 --- a/src/android/BackgroundExt.java +++ b/src/android/BackgroundExt.java @@ -147,6 +147,7 @@ class BackgroundExt { Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); + clearSreenAndKeyguardFlags(); app.startActivity(intent); } @@ -244,10 +245,8 @@ class BackgroundExt { */ private void unlock() { - getApp().runOnUiThread(() -> { - addSreenAndKeyguardFlags(); - getApp().startActivity(getLaunchIntent()); - }); + addSreenAndKeyguardFlags(); + getApp().startActivity(getLaunchIntent()); } /** @@ -287,7 +286,15 @@ class BackgroundExt { */ private void addSreenAndKeyguardFlags() { - getApp().getWindow().addFlags(FLAG_ALLOW_LOCK_WHILE_SCREEN_ON | FLAG_SHOW_WHEN_LOCKED | FLAG_TURN_SCREEN_ON | FLAG_DISMISS_KEYGUARD); + getApp().runOnUiThread(() -> getApp().getWindow().addFlags(FLAG_ALLOW_LOCK_WHILE_SCREEN_ON | FLAG_SHOW_WHEN_LOCKED | FLAG_TURN_SCREEN_ON | FLAG_DISMISS_KEYGUARD)); + } + + /** + * Clears required flags to the window to unlock/wakeup the device. + */ + private void clearSreenAndKeyguardFlags() + { + getApp().runOnUiThread(() -> getApp().getWindow().clearFlags(FLAG_ALLOW_LOCK_WHILE_SCREEN_ON | FLAG_SHOW_WHEN_LOCKED | FLAG_TURN_SCREEN_ON | FLAG_DISMISS_KEYGUARD)); } /**