문제

I have an android project in which I need to save small amount of data. Either 3 tables with 1-20 entries each or 2 dictionaries with nested dictionaries inside (so not only primary data types) or something close to that. These are simply user preferences and login(s) for the server.

I already read about the options for storing data but I don't know which one is the best for my case. I would like to use shared preferences but I am not quite sure that I can store my nested information there. Does it work? Is there a better solution?

My data (example):

  • Server logins: Some keys, including data key. Data contains URL, user, password etc.
  • Favorites: Different info for the items, including server key/data.

The data will be updated rarely, so I can also store some info redundantly to avoid connecting tables or reading from multiple files. The data has to be persistent across sessions and securely stored, not available to any other applications...

도움이 되었습니까?

해결책

I would recommand to use the sqlite Database. This storage is persitent across killed processes and is only private accessable from your App. Have a look here for a first introduction.

SharedPreferences are desigend to store primitive data types, so you cannot easily store nested dictionaries.

Cite from the docs:

The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top