Passing a List from one Activity to another

后端 未结 5 2129
花落未央
花落未央 2020-12-01 13:09

How to pass Collections like ArrayList, etc from one Activity to another as we used to pass Strings, int with help of put

5条回答
  •  攒了一身酷
    2020-12-01 13:49

    I tried all the proposed techniques but none of them worked and stopped my app from working and then I finally succedded. Here is how I did it... In main activity I did this:

                List myList...;
                Intent intent = new Intent...;
                Bundle b=new Bundle();
                b.putStringArrayList("KEY",(ArrayList)myList);            
                intent_deviceList.putExtras(b);
                ....startActivity(intent);
    

    To get the data in the new Activity:

        List myList...
        Bundle b = getIntent().getExtras();
        if (b != null) {
            myList = bundle.getStringArrayList("KEY");
        }
    

    I hope this will help someone...

提交回复
热议问题