java - Using Parceable to pass Objects in android -
wrote class helps pass object, working fine until wanted pass more generic object myself.
public class stepparceble implements parcelable { private step mstep; private jsonobject mstepdata; private onscreen monscreen; public stepparceble(step step, jsonobject stepdata, onscreen onscreen) { setmstep(step); setmstepdata(stepdata); setmonscreen(onscreen); } public stepparceble(parcel parcel){ } public onscreen getmonscreen() { return monscreen; } public void setmonscreen(onscreen monscreen) { this.monscreen = monscreen; } public void setmstep(step mstep) { this.mstep = mstep; } public void setmstepdata(jsonobject mstepdata) { this.mstepdata = mstepdata; } public jsonobject getmstepdata() { return mstepdata; } public step getmstep() { return mstep; } @override public int describecontents() { return 0; } @override public void writetoparcel(parcel dest, int flags) { try { dest.writearray(new object[]{mstep, mstepdata,monscreen}); } catch (exception e) { } } public static final parcelable.creator creator = new parcelable.creator() { public stepparceble createfromparcel(parcel in) { return new stepparceble(in); } public stepparceble[] newarray(int size) { return new stepparceble[size]; } };
}
it return null pointer on getting of values.
passing data
stepparceble stepparceble = new stepparceble(step, stepdata, onscreen); intent uiintent = new intent(context, uiactivity.class).putextra(uicontroltrier.step_key,stepparceble);
you didn't provide means read fields parcelable when you've overridden constructor
public stepparceble(parcel parcel){ //add methods populate fields parcel }
you can use android studio plugins you: https://github.com/mcharmas/android-parcelable-intellij-plugin
also, if class has complex-type fields (like step in case), should parcelable too
Comments
Post a Comment