_persist.setContents( _contacts );
_persist.commit();
}
Create a collection listener to notify the system when a collection changes
The system invokes
CollectionEventSource.addCollectionListener()
to create a
CollectionListener
for each
SyncCollection
the BlackBerry® device application makes available for wireless
backup.
1.
Import the
net.rim.device.api.util.ListenerUtilities
class.
2.
Import the following interfaces:
•
java.util.Vector
•
net.rim.device.api.collection.CollectionEventSource
•
net.rim.device.api.collection.CollectionListener
•
net.rim.device.api.synchronization.SyncCollection
3.
Create a private vector object to store the collection of
SyncCollection
listeners for the BlackBerry device application.
private Vector _listeners;
_listeners = new CloneableVector();
4.
Implement the
CollectionEventSource.addCollectionListener()
method, making sure the method
adds a
CollectionListener
to the
Vector
that contains listeners. In the following code sample, we implement
CollectionEventSource.addCollectionListener()
to invoke
ListenerUtilities.fastAddListener()
to add a listener to the
Vector
that contains listeners.
public void addCollectionListener(Object listener)
{
_listeners = ListenerUtilities.fastAddListener( _listeners, listener );
}
Remove a collection listener that notifies the system when a collection changes
When a
CollectionListener
is no longer required, the system invokes
CollectionEventSource.removeCollectionListener
.
1.
Import the following classes:
•
net.rim.device.api.util.ListenerUtilities
•
java.util.Vector
2.
Import the following interfaces:
•
net.rim.device.api.collection.CollectionEventSource
•
net.rim.device.api.collection.CollectionListener
3.
Implement the following interfaces:
•
net.rim.device.api.collection.CollectionEventSource
Development Guide
Collections
50