Domanda

I am wondering whether the data which was stored in PersistentObject\PersistentStore remains after updating a version of an application.

My use case:

1) Publishing application with version 0.1. Users save data into PersistentObject\PersistentStore

2) Publishing application with version 0.2.

Will the data that was saved into PersistentStore\PersistentObject in version 0.1 be available to the application with version 0.2?

È stato utile?

Soluzione

Yes, it will still be available so long as the classes that are persisted have not had any structural changes. This means you can't add or delete fields between versions if you want the persistent data to remain.

Altri suggerimenti

The best way I've found to ensure this works smoothly when updating the app is to store all your persistent data in a hashtable. Each piece of data will be stored by a string key. You retrieve values by that string key. New versions of the app are able to add new persistent data, simply by adding objects, with new string keys.

This allows you some future flexibility, while not having problems with the basic format of your persistent classes changing, as Michael warned about. Your data will always be in a persistent Hashtable.

If you want to make sure that the persistent data is deleted when your app gets deleted, then use a hashtable container that's unique to your app's package:

package com.mycompany.myapp;

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

public class Preferences extends Hashtable implements Persistable {

An instance of this Preferences class, for example, is what you'll pass to PersistentObject#setContents().

If you don't want the persistent data to be deleted, then just use a standard java.util.Hashtable as the container for all your data.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top