Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I most easily delete Android application data upon upgrade/update?

Tags:

android

So, I have found a bug in a specific sdk that causes it to fail on some Android phones after re-installing a new version of an app which uses the sdk (via adb install -r, and presumably when a user gets an update that has been pushed to the Android market). Is there any way to force an application's data to automatically be cleared upon update of the app? I realize there are different ways that data could be stored, but I just need to essentially simulate an invocation of the "Clear Data" button that'd you find when browsing to the application in the "Manage Applications" section of the Settings (i.e. I just want all data gone).

I am an Android noob and am doing minimal Java coding on this project, so I am basically looking for the simplest solution here. I suppose I could settle on storing a "currentVersion" to disk and then checking it upon launch every time to see if the real current version matches the version that was written to disk on the last launch. Is that the only real way to do this? If so, what's the simplest way to do so?

Thanks!

like image 496
rrbrambley Avatar asked Oct 25 '22 04:10

rrbrambley


1 Answers

Is there any way to force an application's data to automatically be cleared upon update of the app?

No, at least for my definition of "automatic".

I suppose I could settle on storing a "currentVersion" to disk and then checking it upon launch every time to see if the real current version matches the version that was written to disk on the last launch. Is that the only real way to do this?

I'd name it lastKnownVersion, but otherwise this approach seems sound and probably is your only viable option.

If so, what's the simplest way to do so?

Ummm...do exactly what you said. Use Java I/O (storing the file somewhere inside of getFilesDir()), or SharedPreferences.

Bear in mind, though, that your users may get rather frustrated if you blow away their data on an app update. Personally, I'd rather we find a better solution to your original problem ("I have found a bug in a specific sdk that causes it to fail on some Android phones after re-installing a new version of an app which uses the sdk").

like image 170
CommonsWare Avatar answered Nov 17 '22 18:11

CommonsWare