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.
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.
Intent intent = new Intent(getActivity(), StudentResult. class); intent. putExtra("ExtraData", allStudents); startActivity(intent); and in target class to show the objects in ListView();
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With