I have an app that depends on SQLite for data which is populated by xmls shipped with the app in the assets folder.
- When you run the app the first time it sets a shared preference config_run = false.
- then i check if config_run = false then parse the xml and dump the data into db
- set config_run = true
Now i realize that when i have to push an update on Google Play and add more content into the XML. Even though i change the database version from 1 to 2. The import script wont run because shared preference config_run value will be set to true.
Any pointers on how to handle this situation ?
Scenarios
- First Instal - Ver = 1, DB V = 1 (Data is parsed and dumped into the database)
- Bugs Fixed and push and update but no data has changed - ver = 1.1, DB V = 1 (It should just replace the code and not upgrade or re-create the database)
- Upgraded the DATA and pushed a new update - ver 1.2, DB = 2 ( No new code but data has to be re-created)
The Flow of My App
- The App Starts Splash Activity. If Shared Pref - config_run is equal to false then it starts a Progress Dialog and parses and dumps the data into the database.
- Upon Parsing and Creating DB and dumping data it goes to MainActivity.
Second Case
- SplashActivity Runs and config_run = true so directly goes to MAin Activity.
As Suggested by few people below if i try to dumb the data into the database in onUpgrade of the SQLiteHelper it will happen only in MAinActivity as i dont open a Db connection in the SplashActivity and the Dialog Progress wont be displayed also.
onCreate
method of aSQLiteOpenHelper
or manually? – Baten