For my chat app I am looking for a good way to sync messages while the app is in background.
At the moment I have a websocket. When the app comes to foreground, messages get synced. This makes the app looking laggy. Like WhatsApp I need a way to have all messaged synchronized before the app gets in foreground.
I thought about the following solution: I set up a SyncAdapter which gets triggerd by a push notification ("new message for chat xy"). Then inside the SyncAdapter I fetch new messages.
Now the problem is I do not want to connect (e.g. via REST) for each line which has been written. And also I don't want to wait x minutes to bundle new messages.
As I said before, I already have a websocket which gets established when the app goes to foreground. Is it a good idea to move this code to the SyncAadapter? Can I keep the connection open there or should I close it if I dont receive a message for x minutes? The only problem I see is, if an user is not able to receive push messages.
If anyone knows of famous chat apps do it, please point me to this direction.