Add a listener to the message store

  1. Import the required classes and interfaces.
    import net.rim.blackberry.api.mail.NoSuchServiceException;
    import net.rim.blackberry.api.mail.Session;
    import net.rim.blackberry.api.mail.Store;
    
  2. Create a try-catch block to manage a NoSuchServiceException.
    try 
    {
       
    } 
    catch (NoSuchServiceException e) 
    {
       System.out.println(e.toString());
    }
  3. Within the try-catch block, invoke Session.waitForDefaultSession().getStore() to retrieve the Store object.
    try 
    {
       Store store = Session.waitForDefaultSession().getStore();
    } 
    catch (NoSuchServiceException e) 
    {
       System.out.println(e.toString());
    }
  4. After the try-catch block, invoke store.addStoreListener() to add a StoreListener instance to the Store object.
    store.addStoreListener(this);

Was this information helpful? Send us your comments.