Mqtt callback not working when activity is paused / stopped (using paho android service client)

I am using the android paho service client to receive messages from the server using Mqtt. the app works fine for both sending and receiving when work is in progress, but all messages posted when the app starts are not accepted and my Callback class is not running.

I believe this could be a problem in context and that my Callback is tied to my activity context, or I need to somehow wake up my application so that it writes a message to the database and then sleeps again.

here's my MqttCallback implementation:

public class Callback implements MqttCallback{

private Context context;
private static final String TAG = "MQTT";

public Callback(Context context) {
    this.context = context;
}

@Override
public void connectionLost(Throwable arg0) {
    MQTTClient.reconnect(); 
}

@Override
public void deliveryComplete(IMqttDeliveryToken arg0) {
}

@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
    Log.i(TAG,"mesage arrived");
    //update database and store message
}

      

and heres an instance of my client:

    client = newMqttAndroidClient(context,Constants.ADDRESS+Constants.PORT,
    MqttAsyncClient.generateClientId());
    client.setCallback(new Callback(context));

      

the context sent to both is my MainActivity (this)

any guidance would be greatly appreciated.

+3
android service publish-subscribe mqtt paho


source to share


No one has answered this question yet

Check out similar questions:

7
Paho MQTT problem for Android
five
Paho MQTT client behavior when broker / client time goes off
3
Is there a downside to increasing max in flight on Paho MQTT Java client?
3
Android - Paho Mqtt client not receiving messages after changing network connection (mobile data is disabled and re-enabled)
3
Paho-mqtt callbacks in different android java classes
1
Android message PAHO MQTT Archived callback not firing
0
QoS1 vs QoS2 - processing difference with Paho MQTT client in Java
0
Android MQTT client app does not receive publications when app is paused and then resumed
0
PAHO MQTT Android Client for Serving and MainActivity BinderProxy
-2
can MQTT Paho client disconnect asynch?



All Articles
Loading...
X
Show
Funny
Dev
Pics