Hi,
I need to store several promos in the persistant storage. Here's the class:
import net.rim.device.api.util.Persistable;
public class FavoritePromo implements Persistable{
public static String id;
public static String merchantName;
public static String title;
public static String expireDate;
public static String couponsLeft;
public FavoritePromo(String id, String merchantName, String title, String expireDate, String couponsLeft){
this.id = id;
this.merchantName = merchantName;
this.title = title;
this.expireDate = expireDate;
this.couponsLeft = couponsLeft;
}
}
And this is how I put it into the persistant storage:
private static final long PERSISTANCE_KEY_2 = 0xb13951b27c2c948aL;
public static Vector favoritTable = new Vector();
private static PersistentObject persistentObject2 = PersistentStore.getPersistentObject(PERSISTANCE_KEY_2);
public static void addToFavorites(FavoritePromo promo){
synchronized (persistentObject2) {
favoritTable.addElement(promo);
persistentObject2.setContents(favoritTable);
persistentObject2.commit();
}
}
public static void loadFavorites(){
PersistentObject persistentObject2 = PersistentStore.getPersistentObject(PERSISTANCE_KEY_2);
synchronized (persistentObject2) {
favoritTable = (Vector) persistentObject2.getContents();
System.out.println("UserData: Retrieve from RMS success");
}
}
public static void deleteFavorites(){
PersistentStore.destroyPersistentObject(PERSISTANCE_KEY_2);
}
public static boolean isFavorite(String _id){
FavoritePromo tmp;
for (int x = 0; x < favoritTable.size(); x++){
tmp = (FavoritePromo) favoritTable.elementAt(x);
if (tmp.id.equals(_id)) {
return true;
}
}
return false;
}
My two problems are:
Only the first promo actually stored in the persistant storage. The rest are just the same.
When the app is closed and run again, the data is gone. Hmm... isn't it should be persistent?