0

I have created a remote service that takes care of all client-server communication. I have used service because there are few separated applications that will use the same communication socket and there is no other way to "share" socket between applications (as far as i know).

The service works great, can start a socket connection, send and get primitive objects (as int, String, etc...) and works great while sharing same socket between my applications.

As for now, all great and all works fine. The problem starts with different object types. I couldn't figure out to to make my service support passing "Object" through the socket. I've seen a solution that make no sense - using parcels. for example.

In this case, I'll need to create .AIDL file for any object type that I wish my service to support.

Isn't there any way just to use an "Object" type with my service? Any other idea for overcome my obstacle?

Thanks, Lioz.

Sahil Mahajan Mj
  • 11,033
  • 8
  • 53
  • 100
HFDO5
  • 129
  • 3
  • 13

1 Answers1

0

Android IPC uses Parcelable interface to marshal/unmarshal data types. Since Object doesn't implement it, you can't just pass Objects around. You can create your own root type but since every type of Object has a different set attributes that wouldn't be any useful.

See passing objects at AIDL documentation. It should be enough to go through that one.

auselen
  • 27,577
  • 7
  • 73
  • 114
  • Means the only way is implementing separated .AIDL for each object type i would like to use? isn't there any other easier way for my needs? (sharing socket between few apps and send\get Object type through it). thanks – HFDO5 Nov 09 '12 at 23:59
  • You can try to convert marshal/unmarshal your objects at your app level. For example convert them to strings at sending end and convert them back to their original types on the receiving end. Converting them to byte arrays would be more efficient but might be complicated. – auselen Nov 10 '12 at 00:07
  • Thanks, looks like this is the only useful solution for me. I'll start converting data to Strings... – HFDO5 Nov 10 '12 at 14:25