Handling old data in new app versions
When you release a newer version of your application, on update the android system identifies from the package name and version number, that the user has an older version installed. During updating not all data of the previous version is overwritten, databases, preferences, previously downloaded/created files on sdcard or internal storage remain unchanged. If there are any incompatibility with the old version of these, is must be taken care of.
First of all, files on the external storage can be lost or corrupted due to many other reasons, so version incompatibility is just one more reason to check those files before using them.
However the internal storage is theoretically not modified by external sources, if there are version incompatibilities, you have to check the state of this files too.
Values stored in preferences are also unaffected by updating app version. For example if you stored a string under the same key in the previous version, and the current version stores an integer under the same key, the attempt to read the value as an integer can result in a crash.
For databases if you are using the built in SQLiteOpenHelper class it has the onUpgrade method, which you are forced to implement, to handle database version changes. Just be sure to call its constructor with bigger version number when you change the database structure, and the onUpgrade method will be called when first using the database after updating to an application version with a new database structure. Here you can do whatever is needed to solve the issue.
If you can not use the SQLiteOpenHelper class, you must take care of detecting new database version yuorself. With the SQLiteDatabase.setVersion() and getVersion() methods it is not a difficult task anyway.
So, do not forget to test applications by installing them over an older version too, and if there are any problems take care of it.
For example you can compile a constant version number to the builds, and store it in preferences, and check against it on every start. If the data stored by previous versions are incompatible, the easiest solution is to delete, the all the old data to simulate a "fresh" install. But if you want to keep previous user data, you may have to do complex conversions depending on your application.
New tutorials from Helloandroid
Recent Apps
Android on Twitter
-
@Idevicegazette (iDevice Gazette)
GSM-to-Skype bridge lets you lose those roaming fees http://bit.ly/lbRJeh #android
11 years 45 weeks ago -
@tommy_banane (tom b.)
RT @AndroidFavorite: #Android New Desktop Android Market Is Live, Adds Several New Features http://zorr0.nl/lFwXNz
11 years 45 weeks ago -
@dwilliams5 (Dennis Williams)
just completed a runtastic run of 3.02 km in 40 min 11 s with #runtastic #Android App: http://tinyurl.com/5tvrpe3
11 years 45 weeks ago -
@S_Pinz (Spinz!)
RT @Androidheadline: Out of box #LG Optimus 3D got Quadrant 2420 score. Thanks @blink_c #io2011 #android http://twitpic.com/4whkdz
11 years 45 weeks ago -
@tayaitapps (Taya IT)
Next Google TV Looks A Lot Like Android http://t.co/dvlTim3 via @alleyinsider #google #apple #android #tv #honeycomb
11 years 45 weeks ago
Poll
Useful resources
Android Development Projects
- iOS/Android Developer to take older Games and bring them Current
- Android apps developer - need to finish urgent.
- Buliding MobileApp For onlie order
- looking for android APP developers
- Create an ecommerce app
- text-to voice for smartphones IOS - GOOGLE - HARMONY - AND ALEXA
- Optimize Images on App
- Create small feature with drag-drop text for Android
- Scouting for advanced website and Mobile apps developers. Potential Long-term contract.
- BLACK SCREEN