My Java server is receiving a Canvas object from an Android application, and I am trying to send this object out to the other apps. Is it possible to send this without the server having any knowledge of what the object contains, and just simply forward the object without storing it?
Share
Canvas is not serializable, so you won’t be able to do that.
There is private state in Canvas objects that you will not be able to capture, even if you write your own serialization scheme.
You will need to think about some other data structure that is available you. For example, a bitmap can be encoded and written to a stream, and therefore transferred over the network.
Here’s a post that talks about saving a canvas into a bitmap, and then into a jpg,
As for forwarding without storing, you can store whatever you want in memory, so that’s not a problem. You do need to think about the load on the server. If you run into a situation where you have lots of image data in memory. That will exhaust the resources on your server.
As for sending to other apps, you will need to send a C2DM push message to the target device / app that says "there’s something for you on the server, come and get it". For example, when one app puts the data on the server, there’s an ID with it. The C2DM includes this ID, so the target apps do a GET with that ID to retrieve the associated image. Note that the image data will be hanging around in memory for an indefinite amount of time, as there’s no guarantee when or if the C2DM push will get to all the target devices. It might make sense to write the data to a persistent store (like a database or file system), if only temporarily.