After 5 minutes of app inactivity and CometChat.init fired listeners and fetching stop working

my english is not too good but i’ll try.

i’m developing an android integration and i’m having problems with de CometChat.init method and the listeners, about 5 minutes after it fired the listeners (CallListener and MessageListener) stops receives events also the logged in users statuses becomes offline (I need logged in users always are online, and the listener always listen to events) and the only way i have to resolve this is doing a loop each 2 minutes that fires the CometChat.init method again, that’s a bad practice and i’m having problems with the user statuses doing that, i really need a solutions for that requirement please! thank you

Hello @docservi
Can you please let us know the version of the CometChat Android SDK that you are using.

Hi @aditya.gokula , the vesion is com.cometchat:pro-android-chat-sdk:2.0.4-beta1

Hello @docservi,
We have tried this at our end multiple times but our connections seem to be active…in case of network fluctuations the sdk reconnects and the connection is active again…can you please let me know the exact steps to test this so that we can replicate this at our end.

Hi @aditya.gokula, sure, i start app and the CometChat.init method, login method and listener are fire, all work ok, then i stop use de app for some minutes (more than 3 minutes) and then if i send a message or make a call from another user app in other phone, it doesn’t fire event, the listener are sleep (the same happens to me with your test android app), finally when i start using the inactive app again after about 20 seconds it starts receiving events again.

it’s like the CometChat falls asleep while I’m not using it for some minutes and i need to the listernes always are active.

Hello @docservi
Thank you for the information. I just have a few questions to understand the scenario better:

  1. When you are not using the app, is the app in foreground or background
  2. Is the phone asleep (locked) when the app is not being used.
  3. Are you checking this with our UI Kit or you have implemented the functionality in your own app.

From what i can understand, the connection to our web-sockets breaks due to one of the many reasons like network fluctuations or connectivity loss.
The SDK however, is built to reconnect to the web-sockets automatically. This process of reconnection takes around 3-4 seconds and not more on a decent network connection.
We have tested by keeping the app idle for hours and yet the connection is still maintained. There are disconnections but the SDK reconnects every single time.

We would like to inform you that we are in the process of adding connection listeners to the SDK which the developer can use to get real-time events of disconnection and reconnection to the web-sockets server.
This should be released in a couple of days and we will let you know once this is live.

Hope this will solve your problem to identify the state of the web-sockets connection and act accordingly.

Thanks for your patience

Hi @aditya.gokula, the answers are:

1.- yes, i have a backgroud service always running.
2.- the phone can be locked or not, this makes no difference
3.- i test both, on my own app and in your test android app and the result is the same

i found that the XMPP connection falls asleep when you stop using it for a few minutes and the listener to receive messages and calls in real time stops working by the way.

is there any way to mantaing the XMPP connection always awake? i really need that to complete my project, it will be a big project that could generate great income for you.

The only way I found for this was make a loop every 3 minutes to relaunch the CometChat.init method (this mantain the XMPP connection awake and the listeners working ok) but that is not good and the logged in user status fail and the user presences become a crazy thing

Hello @docservi,
Thank you for the detailed information. As we are not able to replicate this at our end, I would like to connect with you over slack to discuss this real-time and come to a solution at the earliest. You can visit the below link and join us on slack:

https://slack.cometchat.com

Once you are on slack, please search for Aditya Gokula and ping me directly and we can take it forward from there.

Thanks

Hi @aditya.gokula, i found the solution and I share it with you:

Android devices sleeps their processor and their WIFI Network after some minutes of inactivity; and the battery optimization service makes the phone sleep apps, te solutions are:

-in the app do a wake lock to prevent the processor goes sleep
-in the app do a WIFI lock to prevent the Wifi network goes sleep
-and add the app to the whitelist of the battery optimization service in programming

all these steps keep the application awake until logout.

thank you so much for your attention!

Hello @docservi,

Glad to see that you have figured out the solution. In case you face any other issues or difficulties in integrating CometChat, please do let us know and we will be happy to help you out.

Thanks

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.