InfoTechEE
asked on
Passing ArrayList<Objects> to another Activity
I am trying to pass an ArrayList of Objects from one Activity to another. I am trying to implement the solution below, but getting an error message. Can someone please help out.
//to pass :
public ArrayList<FileInfo> audioFileArrayList = null;
audioFileArrayList = GetFileInfo(previewName, destFileName);
private ArrayList<FileInfo> GetFileInfo(String strPrevName, String strDestName) {
ArrayList<FileInfo> file_info = new ArrayList<FileInfo>();
FileInfo fi = new FileInfo();
fi.setPrevName(strPrevName );
fi.setDestinationFileName( strDestNam e);
file_info.add(fi);
return file_info;
}
Intent i = new Intent(this, SavedAudio.class);
i.putParcelableArrayListEx tra("ObjAr ray", (ArrayList<? extends Parcelable>) AudioFileArrayList);
startActivity(i);
// to retrieve object in second Activity
ArrayList<FileInfo> fileInfo = getIntent().getParcelableA rrayListEx tra("ObjAr ray");
Error Message:
Bound mismatch: The generic method getParcelableArrayListExtr a(String) of type Intent is not applicable for the arguments (String). The inferred type FileInfo is not a valid substitute for the bounded parameter <T extends Parcelable>
Attached:
FileInfo Class
FileInfo.java
//to pass :
public ArrayList<FileInfo> audioFileArrayList = null;
audioFileArrayList = GetFileInfo(previewName, destFileName);
private ArrayList<FileInfo> GetFileInfo(String strPrevName, String strDestName) {
ArrayList<FileInfo> file_info = new ArrayList<FileInfo>();
FileInfo fi = new FileInfo();
fi.setPrevName(strPrevName
fi.setDestinationFileName(
file_info.add(fi);
return file_info;
}
Intent i = new Intent(this, SavedAudio.class);
i.putParcelableArrayListEx
startActivity(i);
// to retrieve object in second Activity
ArrayList<FileInfo> fileInfo = getIntent().getParcelableA
Error Message:
Bound mismatch: The generic method getParcelableArrayListExtr
Attached:
FileInfo Class
FileInfo.java
ASKER
How do I modify the FileInfo class to be Parcelable?
I didn't realize it would be this difficult to pass an ArrayList from one Activity to another. It sounds like it should be very simple.
Here's a start, but I'm not sure what's suppose to be done here. The Android documentation doesn't make it any simpler either. Any help would be appreciated. Thank you.
import android.os.Parcel;
import android.os.Parcelable;
public class FileInfo implements Parcelable {
private String prevName = "";
private String destinationFileName = "";
public void setPrevName(String previewName) {
this.prevName = previewName;
}
public String getPrevName() {
return prevName;
}
public void setDestinationFileName(Str ing destFileName) {
this.destinationFileName = destFileName;
}
public String getDestinationFileName() {
return destinationFileName;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel arg0, int arg1) {
// TODO Auto-generated method stub
}
}
I didn't realize it would be this difficult to pass an ArrayList from one Activity to another. It sounds like it should be very simple.
Here's a start, but I'm not sure what's suppose to be done here. The Android documentation doesn't make it any simpler either. Any help would be appreciated. Thank you.
import android.os.Parcel;
import android.os.Parcelable;
public class FileInfo implements Parcelable {
private String prevName = "";
private String destinationFileName = "";
public void setPrevName(String previewName) {
this.prevName = previewName;
}
public String getPrevName() {
return prevName;
}
public void setDestinationFileName(Str
this.destinationFileName = destFileName;
}
public String getDestinationFileName() {
return destinationFileName;
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel arg0, int arg1) {
// TODO Auto-generated method stub
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi InfoTechEE,
This is like an android way of doing interprocess communication....For that android defind this data structure called Parcel...
This is simillar to the j2sdk Serialization....
Refer this link....for more details...
http://prasanta-paul.blogspot.in/2010/06/android-parcelable-example.html
This is like an android way of doing interprocess communication....For that android defind this data structure called Parcel...
This is simillar to the j2sdk Serialization....
Refer this link....for more details...
http://prasanta-paul.blogspot.in/2010/06/android-parcelable-example.html
From your Error Message it is clearly visible that FileInfo object should be a Parcelable.
Bound mismatch: The generic method getParcelableArrayListExtr