I want to pass an ArrayList
of LatLng
variables from one Activity
to another through button click.
The one available for String
is not working Please help me out....
I want to pass an ArrayList
of LatLng
variables from one Activity
to another through button click.
The one available for String
is not working Please help me out....
Pass it as an ArrayList of Parcelable objects.
// Put the coordinates
ArrayList<LatLng> coordinates = new ArrayList<>();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("coordinates", coordinates);
// Get the coordinates
coordinates = bundle.getParcelableArrayList("coordinates");
To pass the bundle you need to the intent object you use to invoke the other activity:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtras(bundle);
startActivity(intent);
Then in the SecondActivity's onCreate you fetch the bundle:
ArrayList<LatLng> coordinates = getIntent().getParcelableArrayListExtra("coordinates");