Once again, I'd recommend you change your PersistentStoreHelper
to this version online.
You certainly can get Boolean
and String
values to be deleted from the persistent store when your app is uninstalled, but they need to be inside an object that can only exist in your app.
For example:
PersistentStoreHelper store = PersistentStoreHelper.getInstance();
store.put("flagged", Boolean.TRUE);
// commit will save changes to the `flagged` variable
store.commit();
and then retrieve it later with:
PersistentStoreHelper store = PersistentStoreHelper.getInstance();
boolean isFlagged = ((Boolean)store.get("flagged")).booleanValue();
The key that makes this work is inside my PersistentStoreHelper
class, it saves everything inside a subclass of Hashtable
that's unique to my/your app (MyAppsHashtable
). You need to store your String
or Boolean
objects inside that app-unique Hashtable
subclass, not in a normal java.util.Hashtable
.
Again, please make this easy on yourself, and use the code I posted.
Note: also, you probably know this, but you may need to reboot your device to see the app, and its persistent store data, fully deleted.
Update
If you had changed the original PersistentStoreHelper
class that I had posted online, because you wanted access to the containsKey()
method, or other methods in the Hashtable
class, you can solve that problem by simply adding code like this:
public boolean containsKey(String key) {
return persistentHashtable.containsKey(key);
}
to the PeristentStoreHelper
class. Please don't make persistentHashtable
a public static
member. As you need to use more Hashtable
methods, just add wrappers for them, like I show above with containsKey()
. Of course, you can achieve the same thing as containsKey()
by simply using this code:
boolean containsFlagged = (store.get("flagged") != null);
Update 2
If you get stuck with old persistent data, that you need to clean out, you can modify PersistentStoreHelper
to detect and correct the situation, like this (hattip to @adwiv for suggestions):
private PersistentStoreHelper() {
persistentObject = PersistentStore.getPersistentObject(KEY);
Object contents = persistentObject.getContents();
if (contents instanceof MyAppsHashtable) {
persistentHashtable = (MyAppsHashtable)contents;
} else {
// store might be empty, or contents could be the wrong type
persistentHashtable = new MyAppsHashtable();
persistentObject.setContents(persistentHashtable);
persistentObject.commit();
}
}