passing 2d array to a new activity in android
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
How to pass multidimensional Arraylist to another activity using bundle
You can use Gson library for this, no need to implement serializable.
Suppose your arraylist is :
ArrayList<ArrayList<String>> bigArrayList= new ArrayList<>();
After that, you can add it to the intent as below :
Intent i = new Intent(Activity1.this, Activity2.class);
i.putExtra("data", new Gson().toJson(bigArrayList));
You can later retrieve this in Activity2 as below :
String extra = getIntent().getStringExtra("data");
ArrayList<ArrayList<String>> bigArrayList= new Gson().fromJson(extra, new TypeToken<ArrayList<ArrayList<String>>>(){}.getType());
It works for me! I hope It helps you!
How to pass a 2D array of double between activities?
Convert double 2D array to String 2D array and send it just like you did :
To send :
b.putSerializable("array", other_locations_string);
To get :
String[][] value = (String[][]) b.getSerializable("array");
And then again convert it into double 2d array.
The reason for this behaviour is because Java (and consequently Android) does not let you cast Objects to primitive types, or arrays of primitive types. Why? Because Java considers a valid cast one which converts a super-class object to a sub-class object or vice versa. String[][]
extends Object
, while double and double[][]
do not.
Related Topics
How to Replace a Fragment on Button Click of That Fragment
Intent Filter to Download Attachment from Gmail Apps on Android
Call an Activity Method from a Broadcastreceiver Class
Clicking on Notification Is Not Starting Intended Activity
How to Create Ripple Effect in Simple Layout
Android: HTML Anchor Link Works Only Once in Webview
Cordova Cannot Add Android Failed with Exit Code Enoent
How to Filter Listview Using Getfilter() in Baseadapter
Opening a File from Assets Folder in Android
Get Color Value Programmatically When It's a Reference (Theme)
Obtain Root Access via Su on the Android Emulator
Receive Audio via Bluetooth in Android
Onpagefinished() Never Called (Webview)!
Splash Screen While Loading a Url in a Webview in Android App
How to Set Build and Version Number of Flutter App
CSS Reference to Phone's Emoji Font
A Pre-Populated Database Does Not Work at API 28 Throws "No Such Table" Exception