Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Chat Service

Tags:

android

I am trying to create an application similar to what's up or messenger for learning purpose.

Basically I created an activity that binds to a service which connects to a java server using TCP/IP.

While the service is alive user receives and sends messages. The problem is when the user closes the application (eg using task manager - holding down the Home button). If the application is closed the service is killed becase it has 0 binds.

My question is: What is the pattern of such applications so that the user always receive messages, how does what's up always manages to send messages and keep their service alive.

Thank You.

like image 375
Catalin Avatar asked Nov 14 '22 00:11

Catalin


1 Answers

Chat applications uses both socket connection and GCM/APN. If the app is in foreground, establish a socket connection. When the app is in background, upon receiving a GCM message, again establish a socket connection. This way you will also save the battery. Keeping the socket connection open for a long time will drain the battery of the device. For a sample code, you can refer our android chat sdk:

https://github.com/AppLozic/Applozic-Android-SDK

https://github.com/AppLozic/Applozic-iOS-SDK

like image 95
Devashish Mamgain Avatar answered Dec 24 '22 22:12

Devashish Mamgain