0

I have an ArrayList with drawables and now I want to send them with an Intent to my Service class. How can I do it? My ArrayList:

ArrayList<Drawable> drawableList = new ArrayList<Drawable>();

My Intent:

Intent service = new Intent(this, MyOwnService.class);
                service.putExtra("Dauer", dauer);
                service.putExtra("Links", false);
                startService(service);

I have Bitmaps which I convert to drawables:

        Drawable d = new BitmapDrawable(getResources(),bmp);

How can I put this ArrayList to this Intent?

L3n95
  • 1,505
  • 3
  • 25
  • 49
  • there are all sorts of drawable. depending on what kind of drawables you are trying to send, a different method could apply. (-> please give more details) – njzk2 Apr 24 '14 at 19:16
  • You can try sending the ArrayList of integer reference of the drawable, like R.drawable.my_image – Ariel Magbanua Apr 24 '14 at 19:17
  • @njzk2 look Edit, AT Arman I dont have the drawables in any folder. The drawables are any Pictures the user chooses from his Gallery – L3n95 Apr 24 '14 at 19:19
  • You mean they are physical files in the device's storage? – Ariel Magbanua Apr 24 '14 at 19:21
  • @Lars3n95 : `the user chooses from his Gallery` In this case, you should consider passing the Uris to the pictures, rather than the actual drawable. – njzk2 Apr 24 '14 at 19:46

2 Answers2

1

The way you send messages within an Intent in Android is using the putExtra() method as you did. For the ArrayList you can create a class implementing the Parcelable interface. Here's an example: Arraylist in parcelable object

Community
  • 1
  • 1
yoyosir
  • 458
  • 2
  • 11
  • 27
  • But Drawable "is from Android" how can I let it implement Parelable then? – L3n95 Apr 24 '14 at 19:22
  • You could create some sort of inherited class which can be constructed from an instance of Drawable –  Apr 24 '14 at 19:33
  • @Lars3n95, there is a way to parcel this class:See this http://stackoverflow.com/questions/10070974/how-to-pass-drawable-using-parcelable. But maybe there is a better way of this. I think this must be time consuming.. – yoyosir Apr 24 '14 at 19:57
1

You could maybe simply pass the filenames in a list, so that the intent's receiver will load the files itself (if it can). That seems to be the simplest solution.

Another one would be to create a class that extends Drawable and that can be constructed from an instance of it and that implements the Parcelable interface (so that you can pass it using putExtra())

Another solution that is widely used to tackle this problem but that looks quite ugly (at least to me): you can store your list in a static variable so that it can be accessed from another activity.