android - Passing variables in and out of GCM task service -
i using gcm network manager , want pass service (specifically onruntask(taskparams taskparams)
objects. documentation taskparams string , bundle want pass more complex objects.
how can done?
thank you!
one way have custom object implement parcelable interface , use bundle.putparcelable/bundle.getparcelable.
it requires little more effort use using java's native serialization, it's way faster (and mean way, way faster).
for example:
public class myparcelable implements parcelable { private int mdata; public int describecontents() { return 0; } public void writetoparcel(parcel out, int flags) { out.writeint(mdata); } public static final parcelable.creator<myparcelable> creator = new parcelable.creator<myparcelable>() { public myparcelable createfromparcel(parcel in) { return new myparcelable(in); } public myparcelable[] newarray(int size) { return new myparcelable[size]; } }; private myparcelable(parcel in) { mdata = in.readint(); }
}
also can read parcelable vs serializable
Comments
Post a Comment