im trying to save an arraylist of drawable to a file.
Here is my class.
public class SeccionItem implements Serializable{
String name;
String text;
ArrayList<Drawable> img;
SeccionItem()
{
img = new ArrayList<Drawable>();
}
}
I have an arraylist of that class and i want to write it to a file using objectoutputstream, but i think that drawable cant be serialized, so can i use another type to store the images? like bitmap?. or is there any other way to store that arraylist? overwriting writeObject method?.
Im using this method to download the images
public static Drawable getBitmap(String image_url) {
try {
URL url = new URL(image_url);
InputStream is = (InputStream)url.getContent();
Drawable b= Drawable.createFromStream(is, " ");
if(b==null){
Log.d("this","null");
}
return b;
}catch(Exception ex) {
ex.printStackTrace();
return null;
}
}
neither
Bitmap
orDrawable
areserializable
. You could serialize the information to rebuild yourDrawable
. For instance you could serialize anArrayList<Integer>
where the Intever is the Drawable's id.So you can store it on the sdcard, and nex time you can check if the file exists or not.
To write a file