How to save and retrieve data from ArrayList using shared preference?

216 views Asked by At

Please help me with this. I have more than 70 images. How can I save them using shared preference?

    ArrayList<Integer> list = new ArrayList<Integer>
    list.add(R.drawable.image1);
    list.add(R.drawable.image2);
    list.add(R.drawable.image3);

    position = new Random().nextInt(list.size());
    basic_random_image.setImageResource((Integer)list.get(position));
1

There are 1 answers

0
QArea On

To save images in SharedPreferences is rather a bad idea. If you use images from your res then you can get them when you need by getResources().getDrawable(R.drawable.yourPic). If you download from internet - just save them to SDCard or use some libs for caching images.