Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Pushing Updates on Play Store

I have an app that depends on SQLite for data which is populated by xmls shipped with the app in the assets folder.

  1. When you run the app the first time it sets a shared preference config_run = false.
  2. then i check if config_run = false then parse the xml and dump the data into db
  3. 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

  1. First Instal - Ver = 1, DB V = 1 (Data is parsed and dumped into the database)
  2. 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)
  3. 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

  1. 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.
  2. Upon Parsing and Creating DB and dumping data it goes to MainActivity.

Second Case

  1. 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.

like image 779
Harsha M V Avatar asked Jan 16 '13 15:01

Harsha M V


2 Answers

Add a shared pref of the version number you last ran the script for. On app start, check the current apk version, and if newer, run the script again and update the pref

like image 156
yoah Avatar answered Sep 28 '22 01:09

yoah


Why dont you want use built in sqlite versioning system. DB version is independed from app version. And it does exactly what you want. SQLiteOpenHelper? Every time tou change your db version an onUpgrate callback will be called and you can refill your db. There are a lot of examples.

like image 24
Leonidos Avatar answered Sep 28 '22 00:09

Leonidos