After much searching on the Internet, we came to one conclusion, to ensure a persistent connection to the XMPP server, we need to create a service,
We created one that uses the Smack library to connect to the XMPP server, and it works great with a mobile and Wi-Fi network.
Every time you make something constructive, it always matters !!!, Smack has this reconnection mechanism, which is already implicitly implemented in the library that listens for the connection, and if the connection drops, Smack tries to reconnect to the XMPP server for some interval time.
Our use case:
The INTERNET connection may be due to Wi-Fi or a data network, here, if the connection goes into an idle state, someone turns off the screen, the processor goes into sleep mode, now any data is sent to the server via this connection, there will be no answer, because the server no longer listens to the client, on the client side, the XMPP connection is already connected to the connection. The connection listener does not detect any disconnection from the server, so the thread will terminate.
After searching on INTERNET, we found that the possible solution to this issue is the ping server after the fix (we use 1 minute as the fix period), after detecting the ping error, we implemented the reconnection mechanism just like smack (idea taken from Smack ) using the timer task.
Problem: The only problem is that we have a low battery, if the user is still connected to INTERNET, and the reconnection interval is longer, it will discharge a bit.
1). What is the possible solution to the above problem?
2). Should we use a different approach?