再次,我建议您在线更改PersistentStoreHelper
为此版本。
当您的应用程序被卸载时,您当然可以从持久存储中删除Boolean
和String
删除值,但它们需要位于只能存在于您的应用程序中的对象内。
例如:
PersistentStoreHelper store = PersistentStoreHelper.getInstance();
store.put("flagged", Boolean.TRUE);
// commit will save changes to the `flagged` variable
store.commit();
然后稍后使用以下方法检索它:
PersistentStoreHelper store = PersistentStoreHelper.getInstance();
boolean isFlagged = ((Boolean)store.get("flagged")).booleanValue();
使这项工作的关键在我的PersistentStoreHelper
类中,它将所有内容保存在我/您的应用程序()独有的子类中。您需要将您的或对象存储在该应用程序唯一的子类中,而不是普通的.Hashtable
MyAppsHashtable
String
Boolean
Hashtable
java.util.Hashtable
再一次,请让自己轻松一点,并使用我发布的代码。
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();
}
}