0

I must pass my object with IPC,like this class

public class ForIpc {
    JsonObject info = new JSONObject();
    public void add(String key, String value) {
       info.put(key,value);
    } 
}

ForIpc can implents Parcelable,but how to handle JsonObject?

Foocoder
  • 11
  • 3

1 Answers1

0

You can use the JSON string as the serial representation of the JSONObject.

    @Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeString(info.toString());
}

and parse it back when read from the Parcel.

info = new JSONObject(parcel.readString());
Henry
  • 42,982
  • 7
  • 68
  • 84