How to fill an array from another activity?


Good to all, I want to know how I can fill an array of objects from another activity send the information, and see it in another activity when it is executed.

The idea is like a product selection, I have created a producer class, an adapter extends ArrayAdapter, something like a global variable that I can fill from another actiity.

asked by Alldesign Web 11.05.2017 в 19:46

2 answers


Your producing class should implement the Parcelable interface, and then send them through the Intent with which you call your new Activity

Intent i = new Intent();
Bundle b = new Bundle();
b.putParcelableArrayList("productores",(ArrayList<? extends Parcelable>) ProductoresArray);

answered by 11.05.2017 в 20:15

You mean a Array (and not a List ) this is the solution:

Bundle bundle = new Bundle();
bundle.putStringArray("arrayDatos", new String[]{valor1, valor2});
Intent intent = new Intent(MainActivity.this, ActivityDestino.Class);

in the Activity destination you would receive the bundle containing the Array in this way:

Bundle bundle = this.getIntent().getExtras();
String[] arrayDatos = b.getStringArray("arrayDatos");

If you want to send a List of objects it would be like this:

How can I pass a list of objects from one activity to another?

answered by 11.05.2017 в 21:29