Mr.Moayed Mr.Moayed - 2 months ago 11
JSON Question

How to pass array list between activities

I have this array list and i parsing list item from json like this ,

List<String> imageUrls;

imageUrls = new ArrayList<>();

JSONArray imageArray = response.getJSONObject(feedKey).getJSONArray(entryKey).getJSONObject(i).getJSONArray(imageKey);

for (int j = 0; j < imageArray.length(); j++) {
String imageList = imageArray.getJSONObject(j).getString(labelKey).toString();
imageUrls.add(imageList);
}
appShowModule.setAllimage(imageUrls);


then i try to do this in another activity ,

intent.putStringArrayListExtra("list", appShowModule.getAllimage());


but "appShowModule.getAllimage()" is error ! and how i can received it ?

Answer

Send your list like this

    Intent i = new Intent(this, YourDesiredActiity.class);
    i.putStringArrayListExtra("arrayListToSend",imageUrls);
    startActivity(i);

And then in your desired activity , receive the list like this

   ArrayList<String> urlList = new ArrayList<String>();
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        urlList.addAll(extras.getStringArrayList("arrayListToSend"));
    }

Then you can get your desired arrayList in "urlList"