删除持久对象时,应用程序在黑莓被删除 [英] Delete Persistent Object when app is Deleted in Blackberry

查看:172
本文介绍了删除持久对象时,应用程序在黑莓被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用黑莓持久化对象存储特定于应用程序的配置细节。这里是如何,我实现类

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

推荐答案

创建一个自定义Hashtable类这样的

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{

}  

和改变你的code到

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以下信息

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

黑莓持久性模型

在使用BlackBerry持久化模型中,数据只有在存储包含属于已删除的应用程序数据删除。

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

例如,如果一个应用程序商店的对象,一个叫包 com.mycompany.application.storage 和黑莓智能手机没有其它应用提到了包,持久性存储和删除应用程序都将被删除。

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.

请注意:如果应用程序没有任何对象存储与一个标识封装结构,(例如,一个应用程序商店 java.util.Vector中的 javax.microedition.location.AddressInfo 对象),应用程序应该创建和使用矢量延伸,以一类,以确定矢量属于给定的应用。当存储此矢量,这是由它的包唯一标识,你保证数据是从当应用程序被删除持久性存储中删除。

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.

这<一个href=\"http://supportforums.blackberry.com/t5/Testing-and-Deployment/Handle-stored-data-when-removing-an-application/ta-p/444832\"相对=nofollow>信息就是从这里

这篇关于删除持久对象时,应用程序在黑莓被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆