Possible Duplicate:
How to know my Android application has been upgraded in order to reset an alarm?
I need to run a certain code when my android app is only updated (I specifically want to reschedule alarms).
The did an extensive search on SO and I found that people suggest using SharedPreferences. I dont think this would be correct as sharedPreferences can be deleted upon restart or by simply clearing the cache. Which means when my app is updated, shared preferences may not exist and I may not know if it is an update or simply fresh install ( or even worse a restart).
So, Is there any other way? Perhaps some sort of intent or some sort of method that executes (kinda like onUpgrade for sqlite).
Please advise . Thank you so much
onUpgrade for sqlite simply check if database is present, then what is its version. If Version of current DB is lower then the one in APK it will clear the DB and updated the DB with new one.
Similarly if you clear the application cache. All the file including the DB will be cleared
Similarly you can implement in you application:
like have a static public int version = 1000; in your app. On application on create check if SharedPreferences contains version ( even if SP is not present ) it will return saved or default method.
If value of SP version if less then the current version in your code. Use the updated function which you intent to use.
And if user uninstalls and reinstalled the app then too you might want to register your calls again.