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(strDestName);
            file_info.add(fi);
            
            return file_info;
      }

Intent i = new Intent(this, SavedAudio.class);
i.putParcelableArrayListExtra("ObjArray", (ArrayList<? extends Parcelable>) AudioFileArrayList);
startActivity(i);


// to retrieve object in second Activity
ArrayList<FileInfo> fileInfo = getIntent().getParcelableArrayListExtra("ObjArray");

Error Message:
Bound mismatch: The generic method getParcelableArrayListExtra(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
InfoTechEEAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SanthanaTechnical LeadCommented:
Hi  InfoTechEE,

From your Error Message it is clearly visible that  FileInfo object should be a Parcelable.
Bound mismatch: The generic method getParcelableArrayListExtra(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>
0
InfoTechEEAuthor Commented:
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(String 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
            
      }

}
0
SanthanaTechnical LeadCommented:
Hi  InfoTechEE,

If you pass ArrayList of String it will not give any error... Because internally this String class implements  parcelable...

Refer android docs  http://developer.android.com/reference/android/os/Parcelable.html

mport android.os.Parcel;
import android.os.Parcelable;

public class FileInfo implements Parcelable {

private String prevName = "";
private String destinationFileName = "";

public FileInfo(Parcel source){
prevName = source.readString()
destinationFileName = source.readString();
}
public FileInfo(){
}

public void setPrevName(String previewName) {
this.prevName = previewName;
}

public String getPrevName() {
return prevName;
}

public void setDestinationFileName(String 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 dest, int arg1) {
      dest.writeString(prevName );
      dest.writeString(destinationFileName );
}
}

public static final Parcelable.Creator<FileInfo > CREATOR  =  new Parcelable.Creator<FileInfo >() {
      public FileInfo createFromParcel(Parcel in) {
            return new FileInfo (in);
      }
      public FileInfo [] newArray(int size) {
            return new FileInfo [size];
      }
};
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SanthanaTechnical LeadCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Android

From novice to tech pro — start learning today.