some saftey checks before registering listeners in XmppActivity

This commit is contained in:
iNPUTmice 2014-11-19 17:31:28 +01:00
parent 4b9a507633
commit cbf42ee12c
1 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package eu.siacs.conversations.ui;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
@ -29,6 +30,7 @@ import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
@ -107,7 +109,7 @@ public abstract class XmppActivity extends Activity {
XmppConnectionBinder binder = (XmppConnectionBinder) service;
xmppConnectionService = binder.getService();
xmppConnectionServiceBound = true;
if (!registeredListeners) {
if (!registeredListeners && shouldRegisterListeners()) {
registerListeners();
registeredListeners = true;
}
@ -134,6 +136,15 @@ public abstract class XmppActivity extends Activity {
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
protected boolean shouldRegisterListeners() {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return !isDestroyed() && !isFinishing();
} else {
return !isFinishing();
}
}
public void connectToBackend() {
Intent intent = new Intent(this, XmppConnectionService.class);
intent.setAction("ui");