Reputation: 1191
I would like to pass List<String[]>
through intent to activity and then retrieve it. Anyone know a way on how to do it properly ? Thank you
Upvotes: 0
Views: 1652
Reputation: 31466
It's possible, but you need to pass it as a Serializable and you'll need to cast the result when you extract the extra. Since ArrayList implements Serializable and String[] is inherently serializable, the code is straightforward. To pass it:
ArrayList<String[]> list = . . .;
Intent i = . . .;
i.putExtra("strings", list);
To retrieve it:
Intent i = . . .;
ArrayList<String[]> list = (ArrayList<String[]>) getSerializableExtra("strings");
Upvotes: -1
Reputation: 3756
Put your variable in a static property of an object.
ex.
public class Util {
public static List<String[]> mystaticlist;
}
and access it statically from the second activity:
List<String[]> mystaticlist = Util.mystaticlist;
Upvotes: -1
Reputation: 3996
I would put it in a serializable and then pass the serializable object in the bundle to the next activity.
Bundle bundle = new Bundle();
bundle.putSerializable("list", serializableList);
mainIntent.putExtras(bundle);
startActivity(mainIntent);
java.util.ArrayList
already implements the Serializable
interface. so that would be perfect for your purposes.
Then on the other Activity you can use the following code to retrieve the list
Bundle bundle = getIntent().getExtras();
userInfo = (ArrayList) bundle.getSerializable("list");
Hope it helps.
Upvotes: 5