03-15-2013 06:26 AM
Hello,
I'm trying to persist the sample MessageListDemo and i'm answering me questions.
public static synchronized MessageListDemoStore getInstance()
{
_store = PersistentStore.getPersistentObject(PERSISTENT_STO RE_DEMO_ID);
synchronized(_store)
{
if(_store.getContents() == null)
{
_store.setContents(new MessageListDemoStore());
}
}
_instance = (MessageListDemoStore)_store.getContents();
_store.commit();
return _instance;
}MessageListDemoStore object _instance is persistable ?
03-15-2013 06:38 AM
03-15-2013 07:03 AM
Ok thank you.
I tried that but it doesn't work.
public final class MessageListDemoStore extends Vector implements Persistable
{
public static synchronized Vector getInstance()
{
_store = PersistentStore.getPersistentObject(PERSISTENT_STO RE_DEMO_ID);
synchronized(_store)
{
// If the PersistentObject is empty, initialize it
if(_store.getContents() == null)
{
_store.setContents(new Vector());
}
}
_instance = (Vector)_store.getContents();
_store.commit();
return _instance;
}
If i understand, here, i store contents of my vector in a persistent Storage.
When i receive message i do a cast on _instance to MessageListDemoStore.
Like that i can use all members functions of my class.. it's good ?
03-15-2013 07:41 AM
This is better I think:
public final class MessageListDemoStore extends Vector implements Persistable
{
public static synchronized MessageListDemoStore getInstance()
{
_store = PersistentStore.getPersistentObject(PERSISTENT_STO RE_DEMO_ID);
synchronized(_store)
{
// If the PersistentObject is empty, initialize it
if(_store.getContents() == null)
{
_store.setContents(new MessageListDemoStore());
_store.commit();
}
}
_instance = (MessageListDemoStore)_store.getContents();
return _instance;
}
03-15-2013 09:07 AM
Error message :
C:\Users\Demba\Desktop\eclipse\plugins\net.rim.ejd
com.rim.samples.device.messagelistdemo.MessageList
Packaging project MessageListDemo failed (took 5.42 seconds)
In the MessageListDemoStore there is an over class :
static class ReadableListImpl implements ReadableList
{
private Vector messages;
/**
* Creates a empty instance of ReadableListImpl
*/
ReadableListImpl()
{
messages = new Vector();
}
...
}Readable isn't a persistent class, but it is store in a Vector
03-15-2013 09:11 AM
03-18-2013 05:34 AM
When you think about storage model, you think about an example of an persistant storage ?
When i use extends Vector implements Persistable there is an error :
C:\Users\Demba\Desktop\eclipse\plugins\net.rim.ejd
com.rim.samples.device.messagelistdemo.MessageList
Packaging project MessageListDemo failed (took 6.537 seconds)
03-18-2013 05:44 AM
03-18-2013 10:28 AM
Can i have more explication on the MessageListDemoDeamon please ?
public final class MessageListDemoDaemon extends Application implements ApplicationMessageFolderListener
{
private static final String APPLICATION_NAME = "Message List Demo";
/**
* Called during device startup. Registers application descriptors, message
* folder listeners, message icons and menu items.
*/
void init()
{
// 1. Register folders and application descriptors ----------------------
ApplicationMessageFolderRegistry reg = ApplicationMessageFolderRegistry.getInstance();
// Some context menu items don't need a GUI (e.g. an item for deleting a
// message) and will be run in the current daemon application.
ApplicationDescriptor daemonDescr = ApplicationDescriptor.currentApplicationDescriptor ();
// Main application descriptor - causes application to be launched with
// default welcome screen if a user clicks on the "Message List Demo"
// header in the home screen notifications view.
ApplicationDescriptor mainDescr = new ApplicationDescriptor(daemonDescr, APPLICATION_NAME, new String[] {});
// This application descriptor launches this application with a GUI to
// execute listener callbacks, e.g. to display a message.
ApplicationDescriptor uiCallbackDescr = new ApplicationDescriptor(daemonDescr, APPLICATION_NAME, new String[] {"gui"});
// Get existing messages from storage and register them in folders
ApplicationFolderIntegrationConfig inboxIntegration = new ApplicationFolderIntegrationConfig(true, true, mainDescr);
ApplicationFolderIntegrationConfig deletedIntegration = new ApplicationFolderIntegrationConfig(false);
MessageListDemoStore messages = MessageListDemoStore.getInstance();
ApplicationMessageFolder inbox = reg.registerFolder(MessageListDemo.INBOX_FOLDER_ID , "Inbox", messages.getInboxMessages(),
inboxIntegration);
ApplicationMessageFolder deleted = reg.registerFolder(MessageListDemo.DELETED_FOLDER_ ID, "Deleted Messages", messages.getDeletedMessages(), deletedIntegration);
// Register as a listener for callback notifications
inbox.addListener(this, ApplicationMessageFolderListener.MESSAGE_DELETED | ApplicationMessageFolderListener.MESSAGE_MARKED_OP ENED
| ApplicationMessageFolderListener.MESSAGE_MARKED_UN OPENED | ApplicationMessageFolderListener.MESSAGES_MARKED_O LD, daemonDescr);
deleted.addListener(this, ApplicationMessageFolderListener.MESSAGE_DELETED, daemonDescr);
messages.setFolders(inbox, deleted);
// We've registered two folders, specify root folder name for the
// [View Folder] screen.
reg.setRootFolderName(APPLICATION_NAME);
// 2. Register message icons -------------------------------------------
ApplicationIcon newIcon = new ApplicationIcon(EncodedImage.getEncodedImageResour ce("img/new.png"));
ApplicationIcon readIcon = new ApplicationIcon(EncodedImage.getEncodedImageResour ce("img/read.png"));
ApplicationIcon repliedIcon = new ApplicationIcon(EncodedImage.getEncodedImageResour ce("img/replied.png"));
ApplicationIcon deletedIcon = new ApplicationIcon(EncodedImage.getEncodedImageResour ce("img/deleted.png"));
reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_T YPE, MessageListDemo.STATUS_NEW, newIcon);
reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_T YPE, MessageListDemo.STATUS_OPENED, readIcon);
reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_T YPE, MessageListDemo.STATUS_REPLIED, repliedIcon);
reg.registerMessageIcon(DemoMessage.DEMO_MESSAGE_T YPE, MessageListDemo.STATUS_DELETED, deletedIcon);
// 3. Register message menu items --------------------------------------
ApplicationMenuItem openMenuItem = new OpenContextMenu(0x230010);
ApplicationMenuItem replyMenuItem = new ReplyContextMenu(0x230020);
ApplicationMenuItem markOpenedMenuItem = new MarkOpenedContextMenu(0x230030);
ApplicationMenuItem markUnopenedMenuItem = new MarkUnreadContextMenu(0x230040);
ApplicationMenuItem[] newGuiMenuItems = new ApplicationMenuItem[] {openMenuItem};
ApplicationMenuItem[] newDaemonMenuItems = new ApplicationMenuItem[] {markOpenedMenuItem, replyMenuItem};
ApplicationMenuItem[] openedGuiMenuItems = new ApplicationMenuItem[] {openMenuItem};
ApplicationMenuItem[] openedDaemonMenuItems = new ApplicationMenuItem[] {markUnopenedMenuItem, replyMenuItem};
ApplicationMenuItem[] repliedGuiMenuItems = new ApplicationMenuItem[] {openMenuItem};
ApplicationMenuItem[] repliedDaemonMenuItems = new ApplicationMenuItem[] {markUnopenedMenuItem};
ApplicationMenuItem[] deletedGuiMenuItems = new ApplicationMenuItem[] {openMenuItem,};
reg.registerMessageMenuItems(DemoMessage.DEMO_MESS AGE_TYPE, MessageListDemo.STATUS_NEW, newGuiMenuItems, uiCallbackDescr);
reg.registerMessageMenuItems(DemoMessage.DEMO_MESS AGE_TYPE, MessageListDemo.STATUS_NEW, newDaemonMenuItems, daemonDescr);
reg.registerMessageMenuItems(DemoMessage.DEMO_MESS AGE_TYPE, MessageListDemo.STATUS_OPENED, openedGuiMenuItems, uiCallbackDescr);
reg.registerMessageMenuItems(DemoMessage.DEMO_MESS AGE_TYPE, MessageListDemo.STATUS_OPENED, openedDaemonMenuItems, daemonDescr);
reg.registerMessageMenuItems(DemoMessage.DEMO_MESS AGE_TYPE, MessageListDemo.STATUS_REPLIED, repliedGuiMenuItems, uiCallbackDescr);
reg.registerMessageMenuItems(DemoMessage.DEMO_MESS AGE_TYPE, MessageListDemo.STATUS_REPLIED, repliedDaemonMenuItems, daemonDescr);
reg.registerMessageMenuItems(DemoMessage.DEMO_MESS AGE_TYPE, MessageListDemo.STATUS_DELETED, deletedGuiMenuItems, uiCallbackDescr);
reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_ MESSAGE_TYPE, MessageListDemo.STATUS_NEW, true, false);
reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_ MESSAGE_TYPE, MessageListDemo.STATUS_OPENED, false, true);
reg.setBulkMarkOperationsSupport(DemoMessage.DEMO_ MESSAGE_TYPE, MessageListDemo.STATUS_REPLIED, false, true);
}This is important to modify this class for persistent storage ?
03-18-2013 10:34 AM