# MQTT Disconnect and Reconnects at very short intervals for Android Client

**URL:** <https://community.hivemq.com/t/mqtt-disconnect-and-reconnects-at-very-short-intervals-for-android-client/329>\
**Category:** HiveMQ Client Library\
**Created:** [September 9, 2020, 6:51pm UTC](https://community.hivemq.com/t/mqtt-disconnect-and-reconnects-at-very-short-intervals-for-android-client/329 "2020-09-09T18:51:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shantanu.tigerit](https://avatars.discourse-cdn.com/v4/letter/s/258eb7/32.png) [@shantanu.tigerit](https://community.hivemq.com/u/shantanu.tigerit)\
**Post date:** [September 9, 2020, 6:51pm UTC](https://community.hivemq.com/t/mqtt-disconnect-and-reconnects-at-very-short-intervals-for-android-client/329/1 "2020-09-09T18:51:41Z")

</div>

I’m trying to connect mqtt broker with fixed clientID, it’s working fine but with several reconnect client disconnect and reconnect at very short intervals. Initializing connection from Android service onCreate and cleanup in onDestroy method.

//client builder  
MqttClientBuilder builder = MqttClient.builder()  
.identifier(identifier)  
.serverHost(brokerAddress)  
.serverPort(port)  
.addDisconnectedListener(new MqttClientDisconnectedListener() {  
@Override  
public void onDisconnected(@NotNull MqttClientDisconnectedContext context) {  
Log.e(“hive”,"disconnected " + context.getSource().toString());  
context.getCause().printStackTrace();  
}  
})  
.addConnectedListener(new MqttClientConnectedListener() {  
@Override  
public void onConnected(@NotNull MqttClientConnectedContext context) {  
Log.e(“hive”,“connected”);  
}  
})  
.automaticReconnectWithDefaultConfig();

```
client = builder
        .useMqttVersion3()
        .buildBlocking();
```

---

<div class="post-metadata">

**Author:** ![asmenter15](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@asmenter15](https://community.hivemq.com/u/asmenter15)\
**Post date:** [December 16, 2021, 1:04am UTC](https://community.hivemq.com/t/mqtt-disconnect-and-reconnects-at-very-short-intervals-for-android-client/329/2 "2021-12-16T01:04:24Z")

</div>

I am seeing this as well, my reconnect interval is 5 seconds and I get a disconnect every 5 seconds and an immediate reconnect.

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [December 16, 2021, 9:13am UTC](https://community.hivemq.com/t/mqtt-disconnect-and-reconnects-at-very-short-intervals-for-android-client/329/3 "2021-12-16T09:13:30Z")

</div>

Hi asmenter15,

Welcome to out community forum, we are glad to see your interest in MQTT and HiveMQ!

You indicated that “my reconnect interval is 5 seconds and I get a disconnect every 5 seconds and an immediate reconnect”.

Question: Are you using a unique Client Id for you MQTT Client (this is the string you pass to the `identifier()` method)?

> [@shantanu.tigerit](#):
>
> …  
> MqttClient.builder()  
> .identifier(identifier)  
> …

To get a better advise please feel free to provide an example of your source code.

Kind regards,  
Dasha from HiveMQ Team

---

<div class="post-metadata">

**Author:** ![asmenter15](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@asmenter15](https://community.hivemq.com/u/asmenter15)\
**Post date:** [December 16, 2021, 5:15pm UTC](https://community.hivemq.com/t/mqtt-disconnect-and-reconnects-at-very-short-intervals-for-android-client/329/4 "2021-12-16T17:15:11Z")

</div>

So I saw the unique clientId elsewhere and this did lead me to what I think my issue is, which is actually an instance issue where I have multiple instances of my class that are subscribing with a single clientId so I think each instance is kicking the other instance off when it does it’s own connection flow.

Out of curiosity, when you connect again with the same clientId, do we expect it to kick the existing connection with that clientId? Or will it be rejected since that clientId is already used?

Thank you for the quick response!

---

<div class="post-metadata">

**Author:** ![zingiber](https://avatars.discourse-cdn.com/v4/letter/z/ce73a5/32.png) [@zingiber](https://community.hivemq.com/u/zingiber)\
**Post date:** [December 17, 2021, 11:29am UTC](https://community.hivemq.com/t/mqtt-disconnect-and-reconnects-at-very-short-intervals-for-android-client/329/5 "2021-12-17T11:29:20Z")

</div>

Hey asmenter,

the broker must disconnect the previously connected client when a successful new connect with the same clientId occurs. This mechanism is called “[client take-over](https://www.hivemq.com/blog/mqtt-essentials-part-10-alive-client-take-over/)”.

Kind regards,  
Finn
