Domanda

What is the best way to save multiple (about 80) fields as a single entity? My app creates a "program" object which itself contains about 75 Strings in an array, about 4 other random Strings, and a single int field. I want to be able to save these so that the user will be able to view basic information about each program in a ListView, and then click one of them to view the rest of the data.

What is the best way to save these? I've been thinking about saving them each as their own separate XML file, but I've also heard about databases (though though seem a little much for what I'm trying to do). Or should I just save them as regular .txt files and parse them later? Or maybe even just save every single program in to a single txt/xml file, and parse them all together? Or is there something even more efficient that I'm missing?

È stato utile?

Soluzione

In your case store data into a XML file is the best way. SQLite Database can be used for a stronger work.

Altri suggerimenti

As long as you're not creating a substantial amount of Objects, I'd say that Serializing your Object and storing it that way would be sufficient. If you find yourself creating a number of these Objects I'd suggest you look into a database implementation to handle them.

It depends:

If you want something fast - use SQLite database.

If you want something easy to implement (but slower) - use SharedPreferences.

If you don't want to worry about Cursor or database management just use SharedPreferences. I'm used to serialize/deserialize my objects using GSON, which is easy to setup and works pretty well.

You could have a look at the ObjectOutputStream class too. It can print an object that implements the Serializable interface to a file or other stream.

So you could do something like making an ArrayList of those Strings and int, and write the ArrayList to a file.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top