I developed chat application using Twilio Programmable Chat SDK on Android.
Issue :
There are two users A & B joined to a Channel "AB_Private" and doing chat working fine.
Now user A press home button and put application in background. Twilio SDK detect inactivity and start sending ping to server to keep connection a live.
Working fine for 4-5 minutes but after that twilio disconnect from the socket and start retrieving request. But it never connects till user app is in background.
Now when app comes to foreground, twilio reset the session and try to reconnect but it takes more time to connect, sometime it takes up to 5 minutes.
So my question is how can I keep connection alive with Twilio when application is in background?
Any Help will be appreciated.
Twilio developer evangelist here.
We can't keep the connection when the app is backgrounded, so that's not possible.
The slow reconnection time is probably due to a back off of reconnect attempts which we can try to fix in the SDK.
In the meantime I recommend that you detect when the app is going into background mode and disconnect the chat client. Then, when your user receives another message they will get a push notification at which point you can reconnect the client. Or when the app returns to the foreground, reconnect then.
Let me know if that helps.
Update
This was investigated and deemed a bug within the Twilio SDKs. A fix has just been released to sort this out. Please update to the latest version of the SDK. You can see the changelogs here:
Android:
iOS: