1

I've an application with several activities bounded with a service. The service open, in an asynctask, a socket connection and start listening (while(true)) the incoming message from a socket server.

the question is: how to send a callback to the several activities that a message is arrived?

thanks in advance

Sliver
  • 15
  • 3
  • Maybe like this: http://stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging – zapl Nov 26 '12 at 19:01

1 Answers1

0

Are you binding the activities to the service with onBind()? If so, why? onBind() usually isn't necessary.

As far as I can tell, you're listening for incoming messages from a server. Have you investigated using Google Cloud Messaging?

The activities don't have to be bound to the Service. It will remain running until something shuts it down. You can run an AsyncTask on it, but you might even want to use your own background HandlerThread.

In any event, to communicate back to the activities, use a LocalBroadcastReceiver and send broadcast Intents from the Service.

Joe Malin
  • 8,621
  • 1
  • 23
  • 18
  • yes, i'm binding the activities to the service with onBind() so to access to methods defined in the service. with broadcast intents it works, but i was in doubt that it was the better choice for performace. – Sliver Dec 04 '12 at 00:05