From cbf42ee12cb214e801a0e8473bae93935f70e394 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 19 Nov 2014 17:31:28 +0100 Subject: [PATCH] some saftey checks before registering listeners in XmppActivity --- .../eu/siacs/conversations/ui/XmppActivity.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index e6e97da39..2ff317a4b 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -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");