Ignore harmless errors (un)subscribing to the message bus.

This commit is contained in:
Johannes Mockenhaupt 2018-05-02 22:36:52 +02:00
parent 3b19db14fd
commit 79458a1c73
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 18 additions and 3 deletions

View file

@ -245,12 +245,27 @@ public class MainApp extends Application {
} }
} }
public void stopKeepAliveService() { public void stopKeepAliveService() {
if (keepAliveReceiver != null) if (keepAliveReceiver != null)
KeepAliveReceiver.cancelAlarm(this); KeepAliveReceiver.cancelAlarm(this);
} }
public static void subscribe(Object subscriber) {
try {
bus().register(subscriber);
} catch (IllegalArgumentException e) {
// already registered
}
}
public static void unsubscribe(Object subscriber) {
try {
bus().unregister(subscriber);
} catch (IllegalArgumentException e) {
// already unregistered
}
}
public static Bus bus() { public static Bus bus() {
return sBus; return sBus;
} }

View file

@ -75,7 +75,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
} else { } else {
if (getDialog() != null) if (getDialog() != null)
getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
MainApp.bus().register(this); MainApp.subscribe(this);
running = true; running = true;
} }
} }
@ -97,7 +97,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
MainApp.bus().unregister(this); MainApp.unsubscribe(this);
running = false; running = false;
} }