1

How to pass a 2d String array to new activity???

and then in new activity, How can i retrieve the array??

Dawood Ahmad
  • 51
  • 1
  • 7
  • check: [Pass 2D array to another Activity](http://stackoverflow.com/questions/12214847/pass-2d-array-to-another-activity), [Android - How to pass a double array between activities?](http://stackoverflow.com/questions/12214847/pass-2d-array-to-another-activity) – Paresh Mayani Oct 23 '12 at 06:06
  • You can try this link . hope this will help http://stackoverflow.com/questions/4181885/how-do-you-pass-an-object-array-to-an-activity – Zohaib Brohi Oct 23 '12 at 06:08

1 Answers1

3

You have to use:

 String [][]str;
 Intent summaryIntent = new Intent(this, Second.class);
 Bundle b=new Bundle();
 b.putSerializable("Array", str);
 summaryIntent.putExtras(b);
 startActivity(summaryIntent);

For Recieving the Array use:

Bundle b = getIntent().getExtras();
String[][] list_array = (String[][])b.getSerializable("Array");

Thanks

AppMobiGurmeet
  • 719
  • 3
  • 6
  • i have got error on this line String[][] list_array = (String[][])b.getSerializable("Array"); – Dawood Ahmad Oct 23 '12 at 06:37
  • @ AppMobiGurmeet i don't know it gives force close error on this line – Dawood Ahmad Oct 23 '12 at 06:46
  • @Dawood Ahmad:This is because [][]str is empty.Due to this it may be giving a null pointer exception.Add some data and then check for the result.Can you please provide logs for more clear understanding?.Thanks – AppMobiGurmeet Oct 23 '12 at 06:50
  • String[][] array = new String[][] { { "a", "abc" }, { "b", "bcd" }, { "c", "cde" }, { "d", "def" }, { "f", "fgh" }, }; final Intent summaryIntent = new Intent(this, NewTest.class); Bundle b = new Bundle(); b.putSerializable("Array", array); summaryIntent.putExtras(b); – Dawood Ahmad Oct 23 '12 at 07:00
  • you can use this Bundle b=new Bundle(); b.putStringArray(key, new String[]{value1, value2}); Intent i=new Intent(context, Class); i.putExtras(b); for Reading: Bundle b=this.getIntent().getExtras(); String[] array=b.getStringArray(key); – AppMobiGurmeet Oct 23 '12 at 07:35