paho.mqtt.android icon indicating copy to clipboard operation
paho.mqtt.android copied to clipboard

disconnect when lock screen

Open moo611 opened this issue 2 years ago • 3 comments

moo611 avatar Dec 08 '22 10:12 moo611

Probably its related to the issue I just posted, try to use a foreground service if you don't already. With the foreground service also if it disconnects then i am able to correctly detect disconnection and reconnect it in foreground.

augelloantonio avatar Dec 15 '22 10:12 augelloantonio

did you succeed in reconnecting in a foreground service?

moo611 avatar Dec 22 '22 09:12 moo611

Yes, you need to run a foreground service, check in an handler if you are connected to the mqtt client (i use eventbus for communicating between activities and intercept changes), if not connected the connect again.

To let it work you need to deactivate battery optimization otherwise android won't let your app work in foreground.

To let the app work in foreground personally i do use a persistent notification that keeps the app awake until the user stops the task.

augelloantonio avatar Dec 22 '22 09:12 augelloantonio