tags:

views:

247

answers:

2

How to delete application data on install/reinstall application, so I can have a clean working environment on every reinstall ? I mean how to detect that this application has been reinstalled so I can clean the whole persistent store. Thanks.

A: 

Maybe I'm misunderstanding, but shouldn't your uninstaller just delete the persistent store? Some uninstallers have a checkbox option that lets the user control whether or not their data is uninstalled as well, but it's definitely the uninstaller's job to get rid of it if necessary

Michael Mrozek
I've tried to uninstall the application and then reset and then reinstall the application, the data still there, and I can't find any checkbox to delete the data.
Ari R. Fikri
@Ari Wait, are you asking how to write an uninstaller for your program that deletes the data, or how to use an existing program's uninstaller? I assumed the former; if the latter you're on the wrong website
Michael Mrozek
I want to write a method that my applicaton will completely wipe out all data everytime I reinstall the applicaton. I thought you were pointing me of how to get rid of the data using the blackberry uninstaller.
Ari R. Fikri
+4  A: 

In the 5.0 APIs there is a new class called CodeModuleListener which you could use to monitor when your modules are being uninstalled. Prior to 5.0 though, there are no hooks. However, here are a few ideas to think about and/or try:

  1. Use the CodeModuleManager methods getModuleDownloadTimestamp() or getModuleTimestamp() (not sure which one would give the proper information) to look up the "install time" of the module, then store it in persistence. Then each time the app is started, read the value from the module again and compare it to the persisted value. If the module value is newer, then the app was reinstalled.

  2. If you store a non-native class in the Persistent Store (i.e. a subclass of Hashtable), it will be removed from the persistent store when you uninstall the app (since without the app, the class is meaningless). So all you need to do is create a subclass of Hashtable and store that in your persistent store (with your actual data as keys), and it will be automatically removed from the store when the user uninstalls the app.

Marc Novakowski
1. I must also support from 4.5, so I can't use this codeModuleListener.2. I will create this class :private class CustomHashtable extends Hashtable implements Persistable{ }and change everything that uses Hashtable to this CustomHashtable, but do you think if I reinstall the application the data will come back ?
Ari R. Fikri
I'm not sure - but it would be easy enough to test and find out.
Marc Novakowski
I did it on simulator, but everytime I re-debut/re-run the application, whole previous data was lost. This is not the kind of feature I want actually.
Ari R. Fikri
I have coded multiple programs and used the #2 approach each time. It works very consistently: uninstall the app and the persistent store is gone. As Marc said, use your own classes to be persisted.
ADB
I have retried again and it works. So I accept this solution and mark it as accepted.
Ari R. Fikri