开发者

How to delete application data on install and reinstall

How to delete application data on install/reinstall application, so I can have a clean worki开发者_如何学Gong environment on every reinstall ? I mean how to detect that this application has been reinstalled so I can clean the whole persistent store. Thanks.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜