Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing string array between android activities

Tags:

android

I am having 2 String arrays inside First Activity - A , now i need to pass both the arrays to the second_activity - B, how do i do it ?

I know about the Intent kind of concept in Android and already passed just single variable value to another activity, but i haven't implement the concept of passing string arrays between activities, i have already surfed net for the same.

pls let me know about the possible solution.

like image 710
Paresh Mayani Avatar asked Dec 13 '10 12:12

Paresh Mayani


People also ask

How to Pass array between activities in Android?

putStringArray(key, new String[]{value1, value2}); Intent i=new Intent(context, Class); i. putExtras(b); Hope this will help you. it is just a name with which you want to catch your array in another activity......


2 Answers

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); 
like image 132
viv Avatar answered Sep 21 '22 03:09

viv


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"); 
like image 36
Illegal Argument Avatar answered Sep 23 '22 03:09

Illegal Argument