-3

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 ?

Mr.Moayed
  • 1
  • 5
  • 4
    Possible duplicate of [How to pass ArrayList using putStringArrayListExtra()](http://stackoverflow.com/questions/4030115/how-to-pass-arraylist-using-putstringarraylistextra) – Mike M. Sep 18 '16 at 09:54
  • i edit my question – Mr.Moayed Sep 18 '16 at 10:24
  • You always need to be specific about your errors. What does `getAllimage()` return? If it returns a generic `List`, you'll need to cast it to `ArrayList` to use it there - `(ArrayList) appShowModule.getAllimage()`. The linked duplicate has examples of how to retrieve it in the next `Activity`. – Mike M. Sep 18 '16 at 10:30
  • public List getAllimageurl() { return Allimageurl; } – Mr.Moayed Sep 18 '16 at 10:31
  • in the module i have this private List Allimage = new ArrayList(); public List getAllimage() { return Allimage;} public void setAllimage(List allimage) { Allimage = allimage; } – Mr.Moayed Sep 18 '16 at 10:32

5 Answers5

1

You should implement Parcelable in your class.

Check this best link for easy understanding.

Thanks

Community
  • 1
  • 1
Androider
  • 3,833
  • 2
  • 14
  • 24
0

You can use this method in Intent:

public Intent putExtra(String name, CharSequence[] value)
L. Swifter
  • 3,179
  • 28
  • 52
  • then ? what do in the method ? i wont to passing this array to more than one activity ! how can do this ? – Mr.Moayed Sep 18 '16 at 09:51
0

change List imageUrls to ArrayList imageUrls and intent.putStringArrayListExtra("key",imageUrls);

D.J
  • 1,439
  • 1
  • 12
  • 23
0

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"

Mithun Sarker Shuvro
  • 3,902
  • 6
  • 32
  • 64
0

Add Your Array list to intent from which you are calling another activity

 intent.putStringArrayListExtra("list", yourarraylist);
 startActivity(intent);

To get the array list in activity.

ArrayList list= new ArrayList();
list=  getIntent().getStringArrayListExtra("list");

Hope this will help you.

Prashant Bhoir
  • 900
  • 6
  • 8