java - NotSerializable exception with intent.addExtra(parcelable Object) -


i'm attempting transfer 1 object containing arraylist of other objects activity in android. idea add arraylist , display them task in question can performed.

task ta = new task(n, o, t, v, sublist);      intent = new intent(this, activitylist.class);     i.putextra("task", ta);     startactivity(i); 

this intent. task parcelable, , sublist arraylist of class subtask parcelable. surely, since arraylist implement serializable, parcelling them shouldn't problem? constructor arguments are: string, byte, byte, byte, arraylist. bytes used booleans.

here parcel code task if need it:

@override public void writetoparcel(parcel dest, int flags) {     dest.writestring(taskname);     dest.writebyte((byte) (soundcueone ? 1 : 0));     dest.writebyte((byte) (soundcuetwo ? 1 : 0));     dest.writebyte((byte) (vibrcue ? 1 : 0));     dest.writeserializable(mylist); }  private task(parcel in) {     this.taskname = in.readstring();     this.soundcueone = in.readbyte() != 0;     this.soundcuetwo = in.readbyte() != 0;     this.vibrcue = in.readbyte() != 0;     this.mylist = (arraylist<subtask>) in.readserializable(); }      public static final parcelable.creator creator = new parcelable.creator() {     public task createfromparcel(parcel in) {         return new task(in);     }      public task[] newarray(int size) {         return new task[size];     } }; 

can see wrong code? it's somewhere, maybe in subtask class, since emulator crashes task constructed , tries parcel it.

if see correctly, problem trying use arraylist<t> serializable, though not serializable - parcelable.

therefore, replace

dest.writeserializable(mylist); 

with

dest.writetypedlist(mylist); 

and replace

this.mylist = (arraylist<subtask>) in.readserializable(); 

with

this.mylist = in.readtypedlist(new arraylist<subtask>(), subtask.creator); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -