Is possible store a list within application, without necessarily having a database? Otherwise, what would be the easiest way to store a simple list?
I think it depends on the contents of the list you are working on. If your List is storing "Simple-Objects" only (like List of String List of integer or other Objects with only a few members) you can use SharedPrefenrences which are build in in Android. They need a key and a value. So if your List contains 5 Objects of - lets say Points to keep it simple - you can save them like
SharedPreferences.Editor editor = getSharedPreferences("YourListName", MODE_PRIVATE).edit();
for(int i = 0; i < YOUR_LIST.count() ; i++){
Point p = YOUR_LIST.get(i);
editor.putInt("Element" + i + " X", p.x);
editor.putInt("Element" + i + " Y", p.y);
}
editor.commit();
to recieve this again you could just say
SharedPreferences prefs = getSharedPreferences("YourListName", MODE_PRIVATE);
Map<String, ?> map = prefs.getAll();
There are several ways for Data Storage in Android: Take a look to the developer zone, you have all the information you need there:
Shared Preferences Store private primitive data in key-value pairs.
Internal Storage Store private data on the device memory.
External Storage Store public data on the shared external storage.
SQLite Databases Store structured data in a private database.
Network Connection Store data on the web with your own network server.
Feel free to ask for any type of storage when you already find the one that best fits your needs.
There are multiple persistence alternatives to databases. To name a few (accessible with Java), you can
- Use simple files (with serialisation, or other config format - in that case take a look at commons configuration)
- Write XML content (with XML serialization - again ?!? - or other mechanisms, like XStream, JAXB, ...)
- Use any NoSQL storage (graph DB, document DB, and so on, ...)
- Use prevalence layer (like space4j)
- Use transactionnal data store (like JDBM)
To name only a few of the many storage abilities from Java
There are a couple of ways, look at the doc http://developer.android.com/guide/topics/data/data-storage.html
Java allows you to use serialization of objects with easy API. Here there is a technical article from java web page.
来源:https://stackoverflow.com/questions/6572988/is-it-possible-store-without-a-database-at-android