0

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));
jww
  • 97,681
  • 90
  • 411
  • 885
  • Possible duplicate of [How to use SharedPreferences in Android to store, fetch and edit values](http://stackoverflow.com/questions/3624280/how-to-use-sharedpreferences-in-android-to-store-fetch-and-edit-values). – jww Dec 01 '14 at 03:49
  • BTW, this does not seem like a good idea. Persisting resource IDs seems dangerous. These IDs are auto-generated with each build. So the values that you save may be invalid the next time you build (or the next time a user upgrades). – EJK Dec 01 '14 at 03:51

1 Answers1

0

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.

QArea
  • 4,955
  • 1
  • 12
  • 22