PDA

View Full Version : How to persist models with an image in Byte[] or Drawable format?



Tamuha
5 Mar 2012, 5:25 AM
Hello everyone,

I would like to persist objects with images in my app. Normally I would use the localStorage, but since this can only save Strings, I got a problem.

My first idea would be, to encode each image into a Base64 String and when I load them from the localStorage I would decode them back to Byte[] format.

What do you think about this solution or do you have any other plan/tip/idea?

Thanks in advance!

mitchellsimoens
5 Mar 2012, 7:40 AM
Base64 is the way to go if you want to save to localstorage.

Tamuha
5 Mar 2012, 7:52 AM
Thanks for the fast reply.

But your post makes me curious, which other ways of persisting do I have or would you recommend when working with JSONs?

By the way, one more question which is a bit off-topic:
When I want to use an offline mode in my app (when no internet connection is available, the app should use the localstorage) and you want to just save/persist the username and password in the app, how would you do it? a Store using the localstorage with two strings? (one for username and one for password)

Very big thanks in advance,
tamuha

mitchellsimoens
5 Mar 2012, 8:09 AM
window.navigator.onLine

Tamuha
5 Mar 2012, 8:13 AM
Sorry, I dont get it?!

Tamuha
5 Mar 2012, 3:19 PM
Ok, got it, sry for being so blind.

Just one more thing:
Since the localStorage doenst seem to be the best choice for JSON-objects, what about using Phonegap with SQLite?