本文介绍了删除持久存储数据时,应用被卸载/删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是首次安装应用程序时,一个注册屏幕启动程序(App负载)黑莓应用程序。后来,应用程序将与主屏幕加载。注册画面只出现在第一负载。我通过存储布尔 PersistentStore 实现这一目标。如果该值存在,那么就不会出现登录画面。

I have a BlackBerry application that starts (App load) with a Registration screen when the App is first installed. Later, the App will load with the home screen. Registration screen only appears on first load. I am achieving this by storing a boolean value in PersistentStore. If the value exists, then Registration screen will not appear.

PersistentStoreHelper.persistentHashtable.put("flagged",Boolean.TRUE);
PersistentStoreHelper.persistentObject.commit();
UiApplication.getUiApplication().pushScreen(new MyScreen());

我是知道的事实,为了删除删除/卸载应用程序的持久性存储,我必须作出的哈希表我自己的子类,因此,我已宣布了哈希表中的一个单独的类:

I am aware of the fact that in order to delete the Persistent Store on deleting/uninstalling the App, I have to make the Hashtable a subclass of my own and therefore I have declared the Hashtable in a separate class:

public class PersistentStoreHelper extends Hashtable implements Persistable{

    public static PersistentObject persistentObject;
    public static final long KEY = 0x9df9f961bc6d6daL;
    public static Hashtable persistentHashtable;

}

然而,这并没有帮助和布尔标志值,不是从 PersistentStore 清除。请指点。

However this has not helped and the boolean value of flag is not cleared from PersistentStore. Please advice.

修改:当我更改上面的 PersistentStoreHelper

public static PersistentObject persistentObject =
    PersistentStore.getPersistentObject(KEY);

和删除

PersistentStoreHelper.persistentObject =
    PersistentStore.getPersistentObject(PersistentStoreHelper.KEY);

从B级,其中布尔值被保存,我观察到布尔删除值每一次应用程序被关闭。这是不应该发生的和值只应在情况下,应用程序被删除/卸载删除。任何指针?

from class B where boolean value is being saved, I observe that the boolean value is removed every time the App is closed. This should not happen and the value should only be removed in case the App is deleted/uninstalled. Any pointers?

推荐答案

这工作的方式是BlackBerry OS看着你存储在 PersistentStore 的对象。如果认识到这些对象只能由你的应用程序中使用,那么它会在卸载程序删除它们。然而,如果存储对象的类是由其他应用程序使用的类,那么你的数据的不可以被删除。

The way this works is that the BlackBerry OS looks at the objects you are storing in the PersistentStore. If it recognizes that those objects can only be used by your app, then it will delete them when you uninstall the app. However, if the classes of the stored objects are classes that are used by other apps, then your data will not be deleted.

您已经声明助手类是这样的:

You have declared your helper class like this:

public class PersistentStoreHelper extends Hashtable implements Persistable{

但辅助类不是被存储。您的辅助类仅仅是一个的帮助的,该卖场其他的东西给你。在你的情况下,存储这样的:

but the helper class is not what is being stored. Your helper class is just a helper, that stores other things for you. In your case, it is storing this:

public static Hashtable persistentHashtable;

不过,该对象的类型是的java.util.Hashtable ,这是许多应用程序所使用的一类。因此,它不会被当您卸载应用程序删除。你应该做的是这样的:

but, that object is of type java.util.Hashtable, which is a class used by many apps. So, it won't be deleted when you uninstall your app. What you should do is something like this:

public class PersistentStoreHelper implements Persistable {  // so inner class = Persistable

    public static PersistentObject persistentObject;
    public static final long KEY = 0x9df9f961bc6d6daL;
    /**
      * persistentHashtable is now an instance of a class that
      * only exists in your app
      */
    public static MyAppsHashtable persistentHashtable;

    private class MyAppsHashtable extends Hashtable implements Persistable {
        // don't need anything else ... the declaration does it all!
    }
}

我看不到它在这里,但我假设某处你有这样的code:

I can't see it here, but I'm assuming that somewhere you have this code:

persistentObject = PersistentStore.getPersistentObject(KEY);

,然后当你想将数据保存回店里,你在做这样的事情;

and then when you want to save the data back to the store, you're doing something like this;

persistentHashtable.put("SomeKey", someNewData);
persistentObject.setContents(persistentHashtable);
persistentObject.commit();

只是将数据添加到 persistentHashtable 不保存它(永久)。希望你已经拥有的那部分的地方。

just adding data to the persistentHashtable doesn't save it (permanently). Hopefully, you already had that part somewhere.

注意:如果您做出这些改变,不要期望这行code的工作,下次你运行你的应用程序:

Note: if you make these changes, don't expect this line of code to work, the next time you run your app:

persistentHashtable = (MyAppsHashtable)persistentObject.getContents();

由于您的code最后版本没有使用 MyAppsHashtable 类,所以加载的数据不会被该类型的。这是一个原因,它得到这个权利在第一时间是非常重要的。一般情况下,我总是风节能在 PersistentStore 这是包含在一个顶级的Hashtable 子的,实现持久化。我以后可能会改变它发生的事情,但我永远不会改变的顶级存储对象的签名。希望你还没有公布你的应用程序了。

because the last version of your code did not use the MyAppsHashtable class, so the loaded data won't be of that type. This is one reason that it's important to get this right the first time. In general, I always wind up saving data in the PersistentStore that's contained in one top level Hashtable subclass, that implements Persistable. I may later change what goes in it, but I won't ever change the signature of that top-level storage object. Hopefully, you haven't released your app already.

更新:在回答您的评论/以下问题:

Update: In response to your comment/question below:

if (PersistentStoreHelper.persistentObject.getContents() == null) {
    PersistentStoreHelper.persistentHashtable = new MyAppsHashtable();
    PersistentStoreHelper.persistentObject.setContents(PersistentStoreHelper.persist‌entHashtable);
} else {
    PersistentStoreHelper.persistentHashtable =
        (MyAppsHashtable)PersistentStoreHelper.persistentObject.getContents();
}

这篇关于删除持久存储数据时,应用被卸载/删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 07:06