Is it possible store without a database at android?

元气小坏坏 提交于 2019-12-06 14:23:49

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!