passing a HashMap from one activity to another, android

android

Solution

Use intent.putExtra(String, Serializable) - see http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20java.io.Serializable%29. i.e.

intent.putExtra("placesHashMap", places)

In the receiving activity use

HashMap<String, String> places = (HashMap<String, String>) intent.getSerializableExtra("placesHashMap");

Problem

I am writing an android application to display nearby locations. I stored then in a hashmap list like this ``` List<HashMap<String, String>> places = null; ``` in the first activity I displayed places on a map, and I want to pass them to another activity to list then in a listView. in the first activity I have a button to direct me to the list activity like this: ``` public void list_airports(View v) { Intent intent; switch (v.getId()) { case R.id.list_items: intent = new Intent(getApplicationContext(), List_airports.class); intent.putExtra("places",places); startActivity(intent); break; } } ``` in the next activity I did this: ``` protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_airports); Bundle extras = getIntent().getExtras(); String[] places=extras.getStringArray(Intent.EXTRA_TEXT); ``` but the method putExtra doesn't accept `List<HashMap<String, String>>`

Original source