SharedPreferences used for my Database
I'm trying to create an application that stores GPS data received from a KML file by DDMS;the data is stored in the Sqlite Database.My main problem is that every time I run the application I s开发者_JAVA百科tore the same GPS data in the database,so is a big mess inside my database.Now someone said that I could use SharedPreferences to store a key that tells me if the database already exists assuming that the database exists then is already full.The problem is that I use a SqliteBrowser to create my database and the tabels and I use my code to add information to the tabels.So simply verifying if the tabels exists doesn't help me too much.Has anyone any ideas of how could I manage the Sqlite database so I don't store twice the same data?
There are several possible solutions
1) Check if the data already exists before inserting new data (a simple select statement)
2) Use SQLiteOpenHelper - it provides functions for database version management http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
3) Save information about what has been added in SharedPreferences. You could have a version code or something similar in order to distinguish between different states of the database.
I would suggest that you use either 1 or 2, depending on what you really want to achieve. Maybe you can be a bit more specific about why the data is inserted several times at the moment, what type of data it is (static or dynamically created, web service, etc?)
精彩评论