Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Pass Array to another activity?

I know that we can able to pass the any object with its value to another activity with the method putExtra() and getExtra methods. but now I want to know whether is it possible to pass the array to the another Activity or not? Or if it is then let me know how I can pass the array to the another Activity ? Thanks.

like image 283
Shreyash Mahajan Avatar asked Aug 31 '11 13:08

Shreyash Mahajan


People also ask

How do you pass a value from one activity to another?

Using Intents This example demonstrate about How to send data from one activity to another in Android using intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How pass ArrayList from activity to fragment in Android?

Intent intent = new Intent(getActivity(), StudentResult. class); intent. putExtra("ExtraData", allStudents); startActivity(intent); and in target class to show the objects in ListView();


1 Answers

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

And for receiveing

Bundle b = this.getIntent().getExtras();
String[] array=b.getStringArray(key);
like image 179
Kamal Avatar answered Oct 07 '22 01:10

Kamal