1

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.

Hussain
  • 5,552
  • 4
  • 40
  • 50
Gabrielle
  • 137
  • 1
  • 13

1 Answers1

3

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()?

Community
  • 1
  • 1
Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124