Passing string array between android activities

Bundle b=new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);


Hope this will help you.

In order to read:

Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray(key);

Not directly an answer to the question but you can also use .putStringArrayListExtra() in your bundle. It is more flexible than sending string array.

Bundle b=new Bundle();
b.putStringArrayListExtra("URL_ARRAY_LIST",
                        myStringArrayList);
Intent i=new Intent(context, Class);
i.putExtras(b);

Then you can get this arrayList as follows:

ArrayList<String> urls;
urls = getIntent().getStringArrayListExtra("URL_ARRAY_LIST");

Tags:

Android