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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -