Gabrielle
Gabrielle

Reputation: 137

How to send an array using Bundle?

In my app I have an array

List<Friends> friends =new ArrayList<Friends>();

where Friends is :

import java.io.Serializable;

public class Friends implements Serializable{

private final String name;
private final String id;

public Friends(String name, String id){
    this.name=name;
    this.id=id;
    }
public String getName(){
    return name;
}
public String getId()
{
    return id;
}

}

I want to send this array to an other Activity and I don't know how should I do.

I tried to send them one by one but it not worked. Any idea?

Thanks in advance.

Upvotes: 1

Views: 414

Answers (1)

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28541

ArrayList is Serializable, so Bundle.putSerializable("myList", friendList); should be working.

I would advice however to make your Friend class Parcelable, then use Bundle.putParcelableArrayList()

Note that to pass data to another activity, you should use intent extras. See Passing a Bundle on startActivity()?

Upvotes: 3

Related Questions