How to pass a List using Intent of an Activity for or Activity

0

I need to pass List<Carro> carro using Intent of a Activity to or Activity .

Car is a class with multiple elements String modelo, String categoria Double potencia

    
asked by anonymous 12.04.2017 / 21:36

1 answer

1

First, have your class implement Serializable , example:

public class Carro implements Serializable{}

In your intent you make a cast for serializable:

List<Carro> list = new ArrayList<Carro>();
myIntent.putExtra("LIST", (Serializable) list);

In the second Activity you can get the list like this:

Intent i = getIntent();
list = (List<Carro>) i.getSerializableExtra("LIST");

There are more performative ways to pass parameters between acitivities using Parcelable .

    
12.04.2017 / 22:10