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 @Override
protected void onDestroy() { protected void onDestroy() {
unregisterReceiver(screenOffReceiver); unregisterReceiver(screenOffReceiver);
super.onDestroy(); super.onDestroy();
} }
private void destroyIfNotMain() {
if (getClass() != MainActivity.class)
finish();
}
public void setBroadcastCallback(BroadcastReceivedCallback cb) { public void setBroadcastCallback(BroadcastReceivedCallback cb) {
this.broadcastReceivedCallback = cb; this.broadcastReceivedCallback = cb;
} }
@ -62,12 +56,18 @@ public abstract class BaseActivity extends ThemedActivity {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
if (broadcastReceivedCallback != null) if (broadcastReceivedCallback != null) {
broadcastReceivedCallback.onReceivedScreenOff(); broadcastReceivedCallback.onReceivedScreenOff();
}
if (shouldDestroyOnScreenOff()) {
finish();
}
}
}
}
destroyIfNotMain(); protected boolean shouldDestroyOnScreenOff() {
} return getClass() != MainActivity.class;
}
} }
interface BroadcastReceivedCallback { interface BroadcastReceivedCallback {