Retrieve a collection from persistent storage

  1. Import the following classes:
    • net.rim.device.api.system.PersistentStore
    • java.util.Vector
  2. Import the net.rim.device.api.synchronization.SyncCollection interface.
  3. To provide the BlackBerry® device application 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 );
  4. Store the returned data in a vector object. _contacts = (Vector)_persist.getContents();
  5. Create a method to provide the BlackBerry device application with the newest SyncCollection data before a wireless data backup session begins.
    public void beginTransaction()
    {
    _persist = PersistentStore.getPersistentObject(PERSISTENT_KEY);        
    _contacts = (Vector)_persist.getContents();
    }
  6. 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 );
    _persist.commit();
    }

Index


Was this information helpful? Send us your comments.