oop - Extending an Android Parcelable class -
i have customaddress class extends android.location.address class implements parcelable.
i trying make customaddressimplement parcelableto stuck when creating class parcel. want when creating customaddressfrom parcel first fill in fields super class addressand own fields. have implemented creatorfield:
public static final parcelable.creator<customaddress> creator = new parcelable.creator<customaddress>() { public customaddress createfromparcel(parcel in) { return new customaddress(in); } public customaddress[] newarray(int size) { return new customaddress[size]; } }; but in customaddress(parcel in)creator, can't call super(in)because doesn't exist in android.location.address. can access android.location.address.creator. how fill in fields using creator?
edit: link android address class https://developer.android.com/reference/android/location/address.html
here similar question , mark murphy's excellent answer: https://stackoverflow.com/a/10841502/1140682
so, in case, make customaddress extend address (as do), call super() method in constructor , read own attributes passed parcel. same has done (in same order) in writetoparcel() method, of course here adding attributes parcel.
Comments
Post a Comment