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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With