It's one day work with no solution, I would to passed data beetween activity, I implement Parcelable but from called activity I receive the ListFileMedia with a size=0.
When I mistake?
Class ListFileMedia (Extended of ArrayList)
public class ListFileMedia extends ArrayList<FileMedia> implements Parcelable{
public ListFileMedia(){.....}
// for test i have cancel all methods and var, sure i tested also with...
//Interface Parcelable
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
//dest.writeInt(countIntestazioni);
// Add inner class
dest.writeParcelable(this.add(FileMedia),flags);
}
public ListFileMedia(Parcel in) {
}
public final static Parcelable.Creator <ListFileMedia>CREATOR = new Creator<ListFileMedia>() {
@Override
public ListFileMedia createFromParcel(Parcel source) {
return new ListFileMedia(source);
}
@Override
public ListFileMedia[] newArray(int size) {
return new ListFileMedia[size];
}
};
}
Custom objects in FileListMedia
public class FileMedia implements Comparable,Parcelable{
public String getPath() {return path;}
public String getBucket() {
return bucket;
}
public String getMimeType() { return mimeType; }
private String path;
private String bucket;
private String mimeType;
private int giorno;
private int mese;
private int anno;
public FileMedia(int giorno,int mese,int anno, String path,String bucket,String mimeType){
....
}
public int compareTo(Object o) {
.....
}
//Interface Parcelable
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.path);
dest.writeString(this.bucket);
dest.writeString(this.mimeType);
dest.writeInt(this.giorno);
dest.writeInt(this.mese);
dest.writeInt(this.anno);
}
public FileMedia(Parcel in) {
this.path = in.readString();
this.bucket=in.readString();
this.mimeType=in.readString();
this.giorno=in.readInt();
this.mese=in.readInt();
this.anno=in.readInt();
}
public final static Parcelable.Creator <FileMedia>CREATOR = new Creator<FileMedia>() {
@Override
public FileMedia createFromParcel(Parcel source) {
return new FileMedia(source);
}
@Override
public FileMedia[] newArray(int size) {
return new FileMedia[size];
}
};}
Call activity
ListFileMedia test=new ListFileMedia();
ArrayList arrayList=new ArrayList();
test.add(new FileMedia(10,12,2016,"t","t","t"));
b.putParcelable("list",test);
intent.putExtras(b);
startActivity(intent);
Called activity
Intent intent = this.getIntent();
Bundle b=intent.getExtras();
ListFileMedia listFileMedia (ListFileMedia)b.getParcelable("list"); //size==0 !!!
But if i passed only b.putParcelable("list",new FileMedia(10,12,2016,"t","t","t")
work correctely!!
Sorry for my English..