Add the ability to override destroyOnScreenOff functionality if desired
This commit is contained in:
parent
ba2f911909
commit
f5c6dfc942
1 changed files with 9 additions and 9 deletions
|
@ -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,12 +56,18 @@ 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();
|
||||
}
|
||||
if (shouldDestroyOnScreenOff()) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
destroyIfNotMain();
|
||||
}
|
||||
}
|
||||
protected boolean shouldDestroyOnScreenOff() {
|
||||
return getClass() != MainActivity.class;
|
||||
}
|
||||
|
||||
interface BroadcastReceivedCallback {
|
||||
|
|
Loading…
Reference in a new issue