2

How can i pass array list from one activity to another activity using intent.

From activity

 ArrayList<ServicesInfo> bookedService = new ArrayList<ServicesInfo>();`
  Intent intent = new Intent(getActivity() , Proceedtocart.class);
                intent.putExtra("Listview",bookedService);
                startActivity(intent);

To activity

 bookedService = (ArrayList<BookedInfo>) getIntent().getSerializableExtra("Listview");

while running am getting error as "java.lang.runtimeexception parcel unable to marshal value android"

Help to to fix this issue

3
  • I implemented parcelable in my ServiceInfo array but still same error occuring Commented May 21, 2016 at 5:20
  • Show us your ServiceInfo Commented May 21, 2016 at 5:23
  • Try intent.putParcelableArrayListExtra("key", my_list);. It will solve your problem. For this, you need to make your ServiceInfo parceable. Commented May 21, 2016 at 5:23

2 Answers 2

1

Try this :

Intent intent = new Intent(this, NextActivity.class);
intent.putStringArrayListExtra("Listview", bookedService);
startActivity(intent);

and on NextActivity :

yourArrayList = getIntent().getStringArrayListExtra("Listview");
Sign up to request clarification or add additional context in comments.

Comments

1

You can use

public class ContactInfo {

  private String name;
  private String surname;
  private int idx;

// get and set methods
}



 public class ContactInfo implements Parcelable {

      private String name;
      private String surname;
      private int idx;

    // get and set method

    @Override
        public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(surname);
        dest.writeInt(idx);
    }

    // Creator
    public static final Parcelable.Creator CREATOR
        = new Parcelable.Creator() {
        public ContactInfo createFromParcel(Parcel in) {
        return new ContactInfo(in);
    }

    public ContactInfo[] newArray(int size) {
        return new ContactInfo[size];
        }
    };

    // "De-parcel object
    public ContactInfo(Parcel in) {
        name = in.readString();
        surname = in.readString();
        idx = in.readInt();
    }
} 

Put

Intent i = new Intent(MainActivity.this, ActivityB.class);
// Contact Info
ContactInfo ci = createContact("Francesco", "Surviving with android", 1);
i.putExtra("contact", ci);

Get

Intent i = getIntent();

ContactInfo ci = i.getExtras().getParcelable("contact");

tv.setText(ci.toString()); // tv is a TextView instance

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.