Question

I'am developing something like a Push Notification SDK, when users integrate the SDK to their application, the SDK create a Service and receive Notifications through a TCP connection.

Now here is the question: Assume that many applications will use the SDK on the some android device, all of the application need to receive their own notifications, if we create TCP connection in each Service, it will cost too much resources and battery power, so I want to use a main Service(maybe the first Service start by SDK) to set up TCP connection, the other Services reuse the connection by some kind of IPC. But I don't known what kind of techniques is best to use.

Is there anyone who can give some advice?

thanks~

Was it helpful?

Solution

Finally I solved the problem this way:

Make a public Service(android:export="true") to set up TCP connection to the server, when the APP starts, first check if the public Service exists, if not, call startService(). Then call bindService() in the APP. To communication with the public Service, use a Messenger class:

http://developer.android.com/guide/components/bound-services.html#Messenger

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top