Android Pushing Updates on Play Store

☆樱花仙子☆ 提交于 2020-02-23 09:17:31

问题


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.


回答1:


Instead of setting your shared pref (config_run) to false and making it true, just set the database version into it. When you update your app, check whether you have the same version number in your shared pref. You can do this as shown below:

configRun = settings.getInt("database_version", 0);

if ((DBAdapter.DATABASE_VERSION) == configRun) 
{
//skip xml parsing
}
else
{
//first time configRun will be "0" and DBAdapter.DATABASE_VERSION will be 1
// so you need to parse your xml here and set configRun =1
//on update, change your DB version to 2. now again your configRun and DBAdapter.DATABASE_VERSION will mismatch and you can parse your xml.
}



回答2:


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




回答3:


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.




回答4:


Have your xmlfiles end with the date of the update, and store the last updated date in sharedpref.

On launch you can check search for updates ( in an optimized way ) and if you find a new file with a new date when compared to the last time you know you need to dump the file.

Total hack job :D




回答5:


Two things you can do:

  1. The right way: Override database provider's onUpdate() to import the file. (as suggested above)

  2. The one line changer: Instead of check for key="config_run", you check and set for key=("config_run"+DB_VERSION) to see if import is needed, and of course, if the key does not exist, you should return false. This way every time you update the DB number, import job will run again.

This is agnostic to your app version.



来源:https://stackoverflow.com/questions/14361586/android-pushing-updates-on-play-store

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!