How to force an immediate connection attempt on Android?

"I am using hivemq-mqtt-client:1.3.12 on Android (for a turn-based game.) When the OS blocks the connection (e.g., background restrictions), the client enters DISCONNECTED_RECONNECT.

My issue is that when the user brings the app to the foreground they expect an immediate connection. However:

  • Calling disconnect() throws a MqttClientStateException (not connected).

  • The internal backoff timer doesn’t seem to reset upon calling connect() (or disconnect()) manually.

Is there a supported way to “interrupt” a scheduled reconnection task from outside the DisconnectedListener?

My current choices seem to be either:

  1. Use a super-short maxDelay

  2. Build a new client every time the app is foregrounded and the existing client’s next scheduled connection attempt is too far out

Thanks,

–Eric House