java - Explanation about Parcelable Interface -




i'm studying interface parcelable , i'm facing problems trying understand how works. on internet didn't find answers of questions:

i show class:

public class media implements imodel, parcelable{      private uri uri;     private long _id;     private boolean isondb = false;     private boolean isselected = false;      /*getter , setter methods     ........     */           /***********************************   parcelable **********************************/     public static final parcelable.creator creator = new parcelable.creator<media>(){         @override         public media createfromparcel(parcel parcel) {             return new media(parcel);         }          @override         public media[] newarray(int i) {             return new media[i];         }     };      @override     public int describecontents() {         return 0;     }      @override     public void writetoparcel(parcel parcel, int i) {         parcel.writeparcelable(uri, 1);         parcel.writelong(_id);         parcel.writebyte((byte) (isondb ? 1 : 0));         parcel.writebyte((byte) (isselected ? 1 : 0));     }      private media (parcel parcel){         uri = parcel.readparcelable(uri.class.getclassloader());         _id = parcel.readlong();         isondb = parcel.readbyte() != 0;         isselected = parcel.readbyte() != 0;     } } 

question 1 can see, have constructor 2 field media(uri uri, long _id). problem if method writetoparcel() , constructor private media (parcel parcel) menage 4 fields inside body? mean...the fields managed private media (parcel parcel) , writetoparcel() should reflect number of fields passed "other" contructor?

question 2 how should manage uri field? correct way did it? p.s.: don't understand why can't write parcel.writeserializable(uri); compile error though uri class implements serializable.

thank in advance

is problem if method writetoparcel() , constructor private media (parcel parcel) menage 4 fields inside body?

that should fine.

how should manage uri field? correct way did it?

what have should fine. personally, convert , string, because hate messing classloaders.

i compile error though uri class implements serializable.

uri not implement serializable. implements parcelable. see the javadocs.





wiki

Comments

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

Asterisk AGI Python Script to Dialplan does not work -