Retrieve a collection from persistent storage

  1. Import the required classes and interfaces.
    import java.util.Vector;
    import net.rim.device.api.system.PersistentStore;
    import net.rim.device.api.synchronization.SyncCollection;
  2. To provide the app with access to the newest SyncCollection data from the PersistentStore, invoke the PersistentStore.getPersistentObject() method using the ID of the SyncCollection.
    private PersistentObject _persist; 
    private Vector _contacts; 
    private static final long PERSISTENT_KEY = 0x266babf899b20b56L;
    _persist = PersistentStore.getPersistentObject( PERSISTENT_KEY );
  3. Store the returned data in a vector object. _contacts = (Vector)_persist.getContents();
  4. Create a method to provide the app with the newest SyncCollection data before a wireless data backup session begins.
    public void beginTransaction()
    _persist = PersistentStore.getPersistentObject(PERSISTENT_KEY);        
    _contacts = (Vector)_persist.getContents();
  5. Create code to manage the case where the SyncCollection you retrieve from the PersistentStore is empty.
    if( _contacts == null )
    _contacts = new Vector();
    _persist.setContents( _contacts );
Previous topic: Retrieve persistent data

Was this information helpful? Send us your comments.