Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Data Persistence File Storage Reading from Internal Storage

vicente lee
vicente lee
6,271 Points

SharedPreferences and writing to internal storage

From my understanding, we're trying to write asset images into our internal storage. Could this be done with SharedPreferences and Gson? On a side note, SharedPreferences only deal with internal storage?

aakarshrestha
aakarshrestha
6,509 Points

Are you pulling images from the URL or some servers? If you are, then i would suggest to cache the images in your internal storage... you can use bitmap for images. With SharedPreferences, all the data in the sharepreferences will go away if the app crashes.

You should first know the url of the images you want to write in the internal storage. Then convert the image into bitmap and access the folder in the internal storage in the android device. Create the file in the folder and write in the file with the correct image from the bitmap.

You can use Gson to get the url from the database, if you have the path of the images in the server is stored in the database.

Hope it helps you!

Happy Coding!