MeknessiHamida
MeknessiHamida

Reputation: 185

Send ArrayList inside ArrayList

I have an ArrayList (A) that contains another 2 ArrayLists(B) , I am getting A's data from a json file, in the first activity I can see that A and B both are not empty, but when I pass A to another Activity or a fragment, A stays full but B becomes empty, All the objects used implements Parcelable, this is a snippet of the code used to send and retrieve the data :

           Intent myIntent = new Intent(LauncherActivity.this, AcceuilActivity.class);
                    myIntent.putParcelableArrayListExtra("listeOffres",projectsList);
                    startActivity(myIntent);
                    finish();

and this is how I retrieve A that contains B offresList=getIntent().getParcelableArrayListExtra("listeOffres");

Upvotes: 0

Views: 63

Answers (2)

Haresh Baraiya
Haresh Baraiya

Reputation: 9

I had the same problem and I solved it like this:

Intent myIntent = new Intent(LauncherActivity.this, AcceuilActivity.class);
                myIntent.putExtra("listeOffres",projectsList);
                startActivity(myIntent);
                finish();

and this for how to retrive data

 offresList = (ArrayList<ModelClass>) getIntent().getSerializableExtra("listeOffres");

then implements Serializable Like:

class ModelClass implements Serializable
{}

Upvotes: 1

Krunal Kapadiya
Krunal Kapadiya

Reputation: 3073

Check your Parceble model file. Let's take an example of User here and check below code. Also, check the argument used to passing ArrayList in intent. If this may not help you then please provide more details.

protected User(Parcel in) {
    name = in.readString();
    ....
    gender = in.readString();
}


@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(name);
    ....
    parcel.writeString(gender);
}

Upvotes: 1

Related Questions