0

I want to pass the taskItems

ArrayList<HashMap<String,String>> taskItems = new ArrayList<HashMap<String, String>>();

through intent to the second activity

    ArrayList<String> stringArr = new ArrayList<String>();
    stringArr.add(KEY_TITLE);
    stringArr.add(KEY_INFO);
    stringArr.add(KEY_OBJECT);
    stringArr.add(KEY_LOCATION);

    ArrayList<Integer> intArr = new ArrayList<Integer>();
    intArr.add(R.id.title);
    intArr.add(R.id.info);
    intArr.add(R.id.object);
    intArr.add(R.id.location);

    //Neue Oberfläche starten
    Intent in = new Intent(ListViewActivity.this, ListMenuItemActivity.class);
    in.putStringArrayListExtra("StringAdapter",stringArr);
    in.putIntegerArrayListExtra("intAdapter",intArr);
    ------>in.putStringArrayListExtra("taskItems",taskItems);

    startActivity(in);

I've marked the spot. How can i pass the ArrayList through Intent to my Activity?

  • Make JSONArray of ur list and pass it. – Ankit Kumar Apr 29 '15 at 11:56
  • before posting questions, at least search similar questions available in SO. if you didnt get any solution, then only post. check this question http://stackoverflow.com/questions/15790499/passing-arraylist-of-objects-between-activities – Rince Thomas Apr 29 '15 at 11:57

2 Answers2

2

HashMap extends Serializable interface, so you can pass an ArrayList of Serializable objects:

ArrayList<HashMap<String, String>> taskItems = new ArrayList<>();
in.putExtra("taskItems", taskItems);

and fetch it like:

ArrayList<HashMap<String, String>> taskItems = (ArrayList<HashMap<String, String>>) in
        .getSerializableExtra("taskItems");
Simas
  • 43,548
  • 10
  • 88
  • 116
1

do this way

Send

ArrayList<HashMap<String,String>> hashMap= new ArrayList<HashMap<String, String>>()

Intent intent = new Intent(SourceActivity.this, DestinationActivity.class);
intent.putExtra("hashMap", hashMap);
startActivity(intent);

Recieve

  Intent intent = getIntent();    
   ArrayList<HashMap<String,String>> hashMap = (ArrayList(HashMap<String, String>)) intent.getSerializableExtra("hashMap");
Jignesh Jain
  • 1,518
  • 12
  • 28