views:

31

answers:

2

Initially I use hashtable in my android application. The key point I love hashtable is it is able to store complex item such as: coordinate-->float[2], velocity-->float[2].

But from many samples, using SQLlite table in android seems more efficient but it may only store all the values in one row defined by rowID.

So can anyone enlighten me on this problem? using hash table or SQL lite is more feasible? Can hashtable keep the data if I exit the application?

+1  A: 

Can hashtable keep the data if I exit the application?

No, of course no. A HashTable instance will live while your app is running, but as soon as you close the app, it will be deleted. Now, put your hand in your heart and answer these questions:

  • How much data do you have to save?
  • How often do you use that data?
  • How long should the data persist?

That said, let's talk about more ways to persist data:

  • Shared Preferences if you want an easy way to persist the simple data structures, this is the way to go. In fact, shared preferences allows you to save data in a key<->value schema which is very similar to the HashTable.
  • SQlite this method is really useful, though it's not necessary if you are not saving complex data structures. If you just want to save some values, using SQLite is like killing a fly with a cannon.
  • There are more ways to persist data which I think are not applicable to what you want to do.

So, at first glance, I suggest you take a look at the examples of Shared Preferences, which seems to be ideal for your scenario.

Cristian
let me think about shared preferences. I use some complex data object and therefore i maybe prefer SQL Lite. The only problem i face is learn how to convert complex data type to understandable structure in sql.
aladine
What kind of complex data?
Cristian
As i indicated before. It is a hashtable-similar structure
aladine
object->coor_x, coor_y, vlocity_x, velocity_y
aladine
Well... it's not *that* complex actually. After all, if you are saving all in a `HashTable` you could save it in a Share Preference schema. Or create a table on Sqlite, but it's more complicated and your problem is simple.
Cristian
+1  A: 

SQLite is not more efficient than a hash table. You're really comparing two completely different ideas. SQLite is for persistent storage, a hash table is for volatile storage. What does your application need?

dhaag23
i need persistent storage definitely. So may be I will use SQL lite
aladine