在 Blackberry 中删除应用程序时删除持久对象

发布于 2024-12-29 05:43:50 字数 1012 浏览 2 评论 0原文

我在黑莓中使用持久对象来存储特定于应用程序的配置详细信息。这是我实现该类的方式

public class Preferences implements Persistable
{
    private static  PersistentObject persistentObject = PersistentStore.getPersistentObject(0x2759d6ff72264bdbL);
    private static Hashtable tbl = new Hashtable();

    public static void storeLoginToken(String token)
    {
        token = removeCharAt(token,0);
        token = removeCharAt(token,token.length()-1);
        tbl.put("token", token);
        persistentObject.setContents(tbl);
        persistentObject.commit();
    }

    public static String getLoginToken()
    {
        Hashtable tbl = (Hashtable)persistentObject.getContents();
        try
        {
            String token = tbl.get("token").toString();
            System.out.println("Token = "+token);
            return token;
        }
        catch(Exception e)
        {
            return null;
        }

    }
}

,但是如果我卸载/删除应用程序,这些存储的值不会被删除。当我下次安装该应用程序时,该应用程序将获取旧的存储值。

我怎样才能在黑莓中正确地做到这一点? 谢谢

I am using persistent object in blackberry to store config details specific to the app. Here is how I am implementing the class

public class Preferences implements Persistable
{
    private static  PersistentObject persistentObject = PersistentStore.getPersistentObject(0x2759d6ff72264bdbL);
    private static Hashtable tbl = new Hashtable();

    public static void storeLoginToken(String token)
    {
        token = removeCharAt(token,0);
        token = removeCharAt(token,token.length()-1);
        tbl.put("token", token);
        persistentObject.setContents(tbl);
        persistentObject.commit();
    }

    public static String getLoginToken()
    {
        Hashtable tbl = (Hashtable)persistentObject.getContents();
        try
        {
            String token = tbl.get("token").toString();
            System.out.println("Token = "+token);
            return token;
        }
        catch(Exception e)
        {
            return null;
        }

    }
}

But if I uninstall/delete the app these stored values are not getting deleted. When I installs the app for next time the app is fetching the old stored values.

How can i do this properly in blackberry?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尽揽少女心 2025-01-05 05:43:50

创建一个像这样的自定义哈希表类

package com.myapp.items;


import net.rim.device.api.util.Persistable;

import java.util.*;

public class MyAppHashtable extends Hashtable implements Persistable{

}  

并将您的代码更改为

public class Preferences
{
    private static  PersistentObject persistentObject = PersistentStore.getPersistentObject(0x2759d6ff72264bdbL);
    private static MyAppHashtable tbl = new MyAppHashtable ();

    public static void storeLoginToken(String token)
    {
        token = removeCharAt(token,0);
        token = removeCharAt(token,token.length()-1);
        tbl.put("token", token);
        persistentObject.setContents(tbl);
        persistentObject.commit();
    }

    public static String getLoginToken()
    {
        MyAppHashtable tbl = (MyAppHashtable )persistentObject.getContents();
        try
        {
            String token = tbl.get("token").toString();
            System.out.println("Token = "+token);
            return token;
        }
        catch(Exception e)
        {
            return null;
        }

    }
}

这样我们就可以遵守 RIM 的以下信息

BlackBerry 持久性模型

当您使用 BlackBerry 持久性模型时,仅当存储时才会删除数据包含属于已删除应用程序的数据。

例如,如果应用程序使用名为 com.mycompany.application.storage 的包存储对象,并且 BlackBerry 智能手机上没有其他应用程序引用该包,则持久存储和已删除的应用程序将被删除。

如果对象包装在 Vector 等容器中,情况也是如此。即使 Vector 中只有一个元素具有其他应用程序未使用的包名称,整个 Vector 也会从持久存储中删除。

注意:如果应用程序不存储任何具有标识包结构的对象(例如,存储 java.util.Vector 或 javax.microedition.location.AddressInfo 的应用程序) > 对象),应用程序应创建并使用扩展 Vector 的类,以便识别 Vector 属于给定应用程序。当您存储此 Vector(由其包唯一标识)时,您可以保证在删除应用程序时从持久存储中删除数据。

这个信息来自这里

Create a custom hashtable class like this

package com.myapp.items;


import net.rim.device.api.util.Persistable;

import java.util.*;

public class MyAppHashtable extends Hashtable implements Persistable{

}  

And change your code to

public class Preferences
{
    private static  PersistentObject persistentObject = PersistentStore.getPersistentObject(0x2759d6ff72264bdbL);
    private static MyAppHashtable tbl = new MyAppHashtable ();

    public static void storeLoginToken(String token)
    {
        token = removeCharAt(token,0);
        token = removeCharAt(token,token.length()-1);
        tbl.put("token", token);
        persistentObject.setContents(tbl);
        persistentObject.commit();
    }

    public static String getLoginToken()
    {
        MyAppHashtable tbl = (MyAppHashtable )persistentObject.getContents();
        try
        {
            String token = tbl.get("token").toString();
            System.out.println("Token = "+token);
            return token;
        }
        catch(Exception e)
        {
            return null;
        }

    }
}

This is so that we adhere to the following info from RIM

The BlackBerry persistence model

When you use the BlackBerry persistence model, data is only deleted if the store contains data that belongs to the removed application.

For example, if an application stores an object with a package called com.mycompany.application.storage and no other application on the BlackBerry smartphone makes reference to the package, the persistent store and the removed application are deleted.

The same is true if the object is wrapped in a container such as a Vector. Even if only one of the elements of the Vector has a package name that is not used by other applications, the entire Vector is removed from the persistent store.

Note: If the application does not store any objects with an identifying package structure, (for example, an application that stores java.util.Vector or javax.microedition.location.AddressInfo objects), the application should create and use a class that extends Vector in order to identify that Vector belongs to the given application. When you store this Vector, which is identified uniquely by its package, you guarantee that the data is removed from the persistent store when the application is removed.

This info is from here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文