How to pass ArrayList using putStringArrayListExtra()

后端 未结 4 1607
無奈伤痛
無奈伤痛 2020-12-06 06:13

Hi I want to pass an Arraylist from one activity to another. I use putStringArrayListExtra(), but there shows an error : \"The m

4条回答
  •  难免孤独
    2020-12-06 06:38

    You have to define ArrayList of type String. you can't pass Generic ArrayList in putStringArrayListExtra. Below is the correct code.

    -----
    ArrayList al = new ArrayList();
    ------
    -------
     list_bundle.putStringArrayListExtra("lists",al); 
    ------
    

    Now access this ArrayList in other activity like this.

    ArrayList cl= new ArrayList();
    cl =getIntent().getExtras().getStringArrayList("lists");
    

提交回复
热议问题