MQTT client connection alive even when app is closed

How to keep MQTT client connection alive even when app is to achieve it


I´m not able to give you a cool, little code snippet, that works, but i can point you to the right direction:
You will probably want to use a Service for this: Services need some time to read in, but after that you should be able to achieve to have a client in the background.

Best regards,


I am currently using HIVEMQTT protocol in my android app and I am able to receive messages when my app is open or when it is running in the background however when i close my app completely the connection is lost and I am not longer able to receive messages. I need to be able to still recieve messages as I want the message to trigger an activity in my app to launch.

I guess that you’ll need a foreground service in order to keep it alive while app is closed. See more here: