0

I am trying to implement an Android chat application using web-socket. I am using an Android service to connect to the web socket server. It is working fine, but when I force stop the service (Not the application) manually in task manager

(Settings -> Apps -> Running)

Then my application is not receiving any messages from server. What I observe from other chat applications is even if I stop the background services of those applications, they are receiving messages and after some time the services also automatically started. How is it possible? Is there any other hidden service that wakes up the main application thread?

Vamshi
  • 133
  • 1
  • 9

3 Answers3

0

You can force start the service every time it is force stopped

Take a look at this (How to automatically restart a service even if user force close it?)

Community
  • 1
  • 1
Mohamed Allam
  • 125
  • 2
  • 11
0

Most of those apps are using a push service such as Google Cloud Messaging.

Continually polling servers or maintaining a persistent web socket is not a resource-friendly method of receiving messages from a server over an extended period of time.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
0

To my knowledge, they do not have a special way of doing this. They may have "work arounds" that are convenient (for example, Facebook Messenger can wake the FB app, if you have both installed and stop only 1 of them).

As of Android 3.1, an app cannot wake itself and GCM also will not wake it. See here: GCM push notifications on android 3.1 : disable broadcast receiver

CommonsWare usually knows what he's talking about. Also, I have tested it and it doesn't work for me on the 3.1+ APIs.

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36
  • Thank you @Jim for quick reply. I tried stopping all social media related application services then also if a chat message comes notifications are displaying and the services are starting normally. Is there any service in the google which provide this facility? – Vamshi Sep 04 '15 at 06:10