Saturday, 17 August 2013

What is the best approach for Android Service and data communication

What is the best approach for Android Service and data communication

I am looking for the best approach to share data between a service and 2
different clients (an app and a widget). Currently my application kicks
off a thread that downloads a large amount of data every 15 seconds or so
in the background, stuffs them into an object graph, which is then
consumed by the main app on a configurable time interval. This works for
the primary app but isn't sufficient for the widget that I want to develop
as well, because the object graph will be out of process (and the approach
is kind of messy IMO).
So I am looking to extract the data retrieval part into a service (or if
there is a better suggestion, something else). My question is, what is the
best way to communicate the data received from this service with the
clients? Or would you not use a service and instead use something else?
Because of the overhead on the client, I want the service to notify the
clients when data is ready as opposed to the client continuously polling
the service.....if possible...of course.
I have looked at broadcasting the intent (both app and widget would
receive) but I think I have to serialize the entire object graph and then
inflate it in the client in order to do that. Is that correct? I am
concerned with the speed at which I can accomplish the re-inflate client
side.
Is there a better way to ship the data back to the clients? I would prefer
to ship the objects if that is possible and not serialize...but if that is
the best way, then I will do it.
Any help is greatly appreciated!

No comments:

Post a Comment