How to pass ArrayList>from one activity to another

前端 未结 4 1173
你的背包
你的背包 2020-11-30 02:39

How i can pass Array List from one Activity to another my array list is shown as follows

ArrayList>
4条回答
  •  一生所求
    2020-11-30 03:21

    Use putExtra(String, Serializable) to pass the value in an Intent and getSerializableExtra(String) method to retrieve the data.

    Passing an ArrayList> from Activity A to Activity B

    Intent intent = new Intent(this, B.class);
    HashMap hm = new HashMap();
    hm.put("sunil", "sahoo");
    ArrayList> arl = new ArrayList>();
    arl.add(hm);
    intent.putExtra("arraylist", arl);
    startActivityForResult(intent, 500);
    

    Retrieve the data in Activity B

    ArrayList> arl = (ArrayList>) getIntent().getSerializableExtra("arraylist");
    System.out.println("...serialized data.."+arl);
    

提交回复
热议问题