Add the ability to override destroyOnScreenOff functionality if desired

This commit is contained in:
Joshua Soberg 2021-02-04 20:16:27 -05:00
parent ba2f911909
commit f5c6dfc942

View file

@ -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();
}