j2emanue
j2emanue

Reputation: 62549

android Parcelable when sending object over network

I have a object i want to send over the network in a file to a java servlet. My object looks like this:

public class MYPOJO implements Serializable {

    int myint;
    String mystring;

}

i read its not recommended to use Serializable in Android due to reflection time adding lag. But since its not another activity going to use my object i dont think i should use parcelable. I think i should use Serializable and write the object to disk and then send it over the wire to the java servlet for processing. Writing to disk was figure of speech.writing to java stream rather.

How would you recommend doing this with parcelable is the question, is it even possible ? is is paracelable only recommended from activity to another Activity ?

Upvotes: 0

Views: 411

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

I think i should use Serializable and write the object to disk and then send it over the wire to the java servlet for processing.

I don't know why you would need to write it to disk. You can write it to an ObjectOutputStream backed by a ByteArrayOutputStream and skip the disk I/O.

Personally, I'd never in a million years use Serializable for network I/O (use JSON or protobuf or something else platform-neutral), but if you are going to use it, at least be efficient about it. :-)

How would you recommend doing this with parcelable is the question, is it even possible ?

No. Parcelable is for inter-process communication, not network transport, persistence, or other scenarios outside the running device.

is is paracelable only recommended from activity to another Activity ?

You are welcome to use it for other IPC scenarios (e.g., remote service with Parcelable AIDL method parameters).

Upvotes: 1

Related Questions