Android Service deny websocket from receive messages?


Hello everybody! Here with a fresh new problem.   Now I'm stucked on Android services. I'm trying to use a push system, using the free version of sgcWebSocket that works fine. Usually, I just set the client component to listen to a weksocket, get the text and trigger a push notification. This works very well. Now, I'm trying to move the websocket into an android service. I looked the sample project that works with notifications but something is wrong or I can't just figure out. This is the code in OnStartCommand event in my service:

sgcWebSocketClient1.Active := True;
Result := TJService.JavaClass.START_STICKY;

As you can see, I try to activate the client right there. So I expect than from now on, if the service is running, I should be able to receive Text on the client, but it does not happen. The websocket does not trigger the OnMessage event even if actually it receive messages - I'm totally sure about it. There is a sample project that shows me the same code, but it's strange: in the sample, the service stops after sending a push. Why? And still... If is "STICKY" should'nt run again after being closed? Just to be clear, the final result I'm trying to obtain is something like Whatsapp, an application that you don't really "close", it keeps opened in background and if receive e message notify it with a push. One last note... In the sample project there is a not used var... It's a TThread. >_> Am I missing something? I have to work with threads may be? To be fair I tryed something with thread, initializing the websocket in a anonymous thread... but still no results. Please help me xD   Thanks in advance!

Responses (1)
Your Reply

Please login to post a reply.........