diff --git a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java index 06e5b7e98..3d27e8bff 100755 --- a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java +++ b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttAndroidClient.java @@ -54,8 +54,11 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Bundle; +import android.os.Handler; +import android.os.HandlerThread; import android.os.IBinder; import android.support.v4.content.LocalBroadcastManager; +import android.os.Looper; import android.util.SparseArray; /** @@ -444,11 +447,18 @@ public void run() { return token; } + private Handler handler; private void registerReceiver(BroadcastReceiver receiver) { + if (handler == null) { + HandlerThread handlerThread = new HandlerThread("MyNewThread"); + handlerThread.start(); + Looper looper = handlerThread.getLooper(); + handler = new Handler(looper); + } IntentFilter filter = new IntentFilter(); - filter.addAction(MqttServiceConstants.CALLBACK_TO_ACTIVITY); - LocalBroadcastManager.getInstance(myContext).registerReceiver(receiver, filter); - receiverRegistered = true; + filter.addAction(MqttServiceConstants.CALLBACK_TO_ACTIVITY); + myContext.registerReceiver(receiver, filter, null, handler); + receiverRegistered = true; } /** diff --git a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java index 626c5b896..c6c42034f 100644 --- a/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java +++ b/org.eclipse.paho.android.service/src/main/java/org/eclipse/paho/android/service/MqttService.java @@ -283,7 +283,7 @@ void callbackToActivity(String clientHandle, Status status, if (dataBundle != null) { callbackIntent.putExtras(dataBundle); } - LocalBroadcastManager.getInstance(this).sendBroadcast(callbackIntent); + sendBroadcast(callbackIntent); } // The major API implementation follows :-