Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Executing code only on first run and every subsequent upgrade

Tags:

android

I have some code that generates a "read me" dialog and does some initial directory creation on the sd card, which currently resides in the onCreate method... I would like to segregate this code and have it execute only once, at the apps first run.. and then after all subsequent upgrades. I've noticed that most apps on the market do this, yet have not figured out how to implement it in mine yet... any help would be appreciated.

like image 372
Frank Bozzo Avatar asked Oct 05 '10 14:10

Frank Bozzo


1 Answers

What I do is this: I save the apps version in its preferences and compare if the version changed. If it did, I display a dialog with information on whatever's new in this version and write the current version to the preferences.

This way the dialog will only appear once after each upgrade.

Check this page for SharedPreferences:
http://developer.android.com/reference/android/content/SharedPreferences.html

And this is how to get the version name of your app:
http://android.hlidskialf.com/blog/code/android-get-version-name

like image 166
Select0r Avatar answered Oct 19 '22 02:10

Select0r