Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:01:28+00:00 2026-05-23T05:01:28+00:00

I am currently trying to pass an ArrayList of objects from one activity to

  • 0

I am currently trying to pass an ArrayList of objects from one activity to another. After much searching, I saw that you could pass things as parcels. Here is what I ended up doing:

public class PartsList extends ArrayList<Part> implements Parcelable {

public PartsList(){

}

public PartsList(Parcel in){

}

@SuppressWarnings("unchecked")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
    public PartsList createFromParcel(Parcel in) {
        return new PartsList(in);
    }

    public Object[] newArray(int arg0) {
        return null;
    }
};

private void readFromParcel(Parcel in) {
    this.clear();

    // read the list size
    int size = in.readInt();

    // order of the in.readString is fundamental
    // it must be ordered as it is in the Part.java file

    for (int i = 0; i < size; i++) {
        Part p = new Part();
        p.setDesc(in.readString());
        p.setItemNmbr(in.readString());
        p.setPrice(new BigDecimal(in.readString()));
        this.add(p);
    }
}


@Override
public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public void writeToParcel(Parcel arg0, int arg1) {
    int size = this.size();

    arg0.writeInt(size);

    for (int i = 0; i < size; i++) {
        Part p = this.get(i);
        arg0.writeString(p.getDesc());
        arg0.writeString(p.getItemNmbr());
        arg0.writeString(p.getPrice().toString());
    }
}
    }

And here is the part Object:

public class Part implements Parcelable{
private String desc;
private String itemNmbr;
private BigDecimal price;

public Part(){

}

public Part(String i, String d, BigDecimal p){
    this.desc = d;
    this.itemNmbr = i;
    this.price = p;
}

It also has getters/setters of course.

This is where the list is created:

for (String i : tempList){
        Matcher matcher = pattern.matcher(i);
        while (matcher.find()){

            // getting matches
            String desc = matcher.group(6);
            String item = matcher.group(9);
            BigDecimal price = new BigDecimal(matcher.group(12).toString());

            // adding the new part to the parts list
            parts.add(new Part(item, desc, price));
        }
    }

Now, here is where it is received:

    public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  // get extras (list)
  Bundle b = getIntent().getExtras();
  parts = b.getParcelable("parts");
//    Part[] PARTS = (Part[]) parts.toArray();
  final Part[] PARTS = new Part[] {
    new Part("desc", "item id", new BigDecimal(0))    
  };
  final String[] COUNTRIES = new String[] {
        "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra"
      };
  setListAdapter(new ArrayAdapter<Part>(this, R.layout.list_item, PARTS));

  ListView lv = getListView();
  lv.setTextFilterEnabled(true);

  lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
      // When clicked, show a toast with the TextView text
      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
          Toast.LENGTH_SHORT).show();
    }
  });
}

If I don’t use the parcel, and just use the array – it works fine. I commented out my test list and it worked fine, otherwise it crashed.

//          parts.add(new Part("desc", "item id", new BigDecimal(0)));
//          parts.add(new Part("desc2", "item id2", new BigDecimal(1)));
//          parts.add(new Part("desc3", "item id3", new BigDecimal(2)));
        // create a new bundle
        Bundle b = new Bundle();

        // put the list into a parcel
        b.putParcelable("parts", parts);
        Intent i = new Intent(SearchActivity.this, Results.class);

        // put the bundle into the intent
        i.putExtras(b);
        startActivity(i);

Did I do something wrong with the implementation of the Parcel? I can’t figure this out. If anyone could help me ASAP – that would be amazing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:01:29+00:00Added an answer on May 23, 2026 at 5:01 am

    In your implementation of Parcelable.Creator, this looks sketchy:

    public Object[] newArray(int arg0) {
        return null;
    }
    

    I believe it should be:

    public Object[] newArray(int arg0) {
        return new PartsList[arg0];
    }
    

    You also need to define your CREATOR object for Part if you’re going to declare it to implement Parcelable (although I’m not sure why it needs to).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem in trying to pass a ArrayList Object from Activity
I am currently trying to pass data from my server to my main page.
I am currently trying to call a method from a utility class that will
I am currently trying to pass in some html into the the :after pseudo
I'm currently trying to pass PCI compliance for one of my client's sites but
I am currently trying to separate my Views as much as possible from my
I'm currently trying to pass Silverlight a string value from the parent JavaScript. The
I'm currently trying to pass a mono threaded program to multithread. This software do
I am currently trying to pass a generated JSON string to dojo for parsing
I am currently trying to create a function which will allow me to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.