From f5c6dfc942d227cc8e20e882fdb6e164d1b847ae Mon Sep 17 00:00:00 2001 From: Joshua Soberg Date: Thu, 4 Feb 2021 20:16:27 -0500 Subject: [PATCH] Add the ability to override destroyOnScreenOff functionality if desired --- .../flocke/andotp/Activities/BaseActivity.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/BaseActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/BaseActivity.java index 108adca3..f74fdfc6 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/BaseActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/BaseActivity.java @@ -43,15 +43,9 @@ public abstract class BaseActivity extends ThemedActivity { @Override protected void onDestroy() { unregisterReceiver(screenOffReceiver); - super.onDestroy(); } - private void destroyIfNotMain() { - if (getClass() != MainActivity.class) - finish(); - } - public void setBroadcastCallback(BroadcastReceivedCallback cb) { this.broadcastReceivedCallback = cb; } @@ -62,14 +56,20 @@ public abstract class BaseActivity extends ThemedActivity { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { - if (broadcastReceivedCallback != null) + if (broadcastReceivedCallback != null) { broadcastReceivedCallback.onReceivedScreenOff(); - - destroyIfNotMain(); + } + if (shouldDestroyOnScreenOff()) { + finish(); + } } } } + protected boolean shouldDestroyOnScreenOff() { + return getClass() != MainActivity.class; + } + interface BroadcastReceivedCallback { void onReceivedScreenOff(); }