Passing ArrayList of string arrays from one activity to another in android

Not sure what you mean by “ArrayList of string arrays”

If you have string array then check the below link

Passing string array between android activities

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

ArrayList implements Serializable

You can use intents

    ArrayList<String> mylist = new ArrayList<String>();  
    Intent intent = new Intent(ActivityName.this, Second.class);
    intent.putStringArrayListExtra("key", mylist);
    startActivity(intent);

To retrieve

    Intent i = getIntent();  
    ArrayList<String> list = i.getStringArrayListExtra("key");

public Intent putStringArrayListExtra (String name, ArrayList<String> value)

Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like “com.android.contacts.ShowAll”.

Parameters

name    The name of the extra data, with package prefix.
value   The ArrayList data value.

Returns

Returns the same Intent object, for chaining multiple calls into a single statement.

To pass ArrayList of String array

String[] people = {
        "Mike Strong",
        "Jennifer Anniston",
        "Tom Bennet",
        "Leander Paes",
        "Liam Nesson",
        "George Clooney",
        "Barack Obama",
        "Steve Jobs",
        "Larry Page",
        "Sergey Brin",
        "Steve Wozniak"
};
String[] people1 = {
        "raghu", 
        "hello"
};


ArrayList<String[]> list = new ArrayList<String[]>();
list.add(people);
list.add(people1);
Intent i = new Intent(MainActivity.this,SecondActivity.class);
i.putExtra("key", list);
startActivity(i); 

To retrieve

Intent in = getIntent();
ArrayList<String[]> list =(ArrayList<String[]>) in.getSerializableExtra("key");
for(int i=0;i<list.size();i++)
{
   String s[]= list.get(i);
   for(int iv=0;iv<s.length;iv++)
   Log.i("..............:",""+s[iv]);
}

Leave a Comment