1

I want to have a listener when a message is opened from the application messages folder. For this I make use of ApplicationMenuItem, but after registering it, the message could not be opened anymore.

ApplicationMessageFolderRegistry messagefolderRegistry = ApplicationMessageFolderRegistry.getInstance();
        messaageMenuItemListener = new CVSMessaageMenuItemListener();
        CVSApplicationMenuItem menuItem = new CVSApplicationMenuItem();
        menuItem.registerMenuItemListener(messaageMenuItemListener);        
        messagefolderRegistry.registerMessageMenuItems(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, new ApplicationMenuItem[]{menuItem});
        messagefolderRegistry.registerMessageIcon(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, alarmsIcon);

and the menuItem:

public class CVSApplicationMenuItem extends ApplicationMenuItem {

    private CVSVector listeners;

    CVSApplicationMenuItem(){
        super(20);
    }

    public Object run(Object context) {
        if(!(context instanceof CVSApplicationMessage))
            return context;

        CVSApplicationMessage applicationMessage = (CVSApplicationMessage)context;
        if(listeners == null)
            return context;

        for (int i = 0; i < listeners.size(); i++) {
            ((ICVSApplicationMessageMenuItemListener)listeners.itemAt(i)).messageReaded(applicationMessage);
        }
        return context;
    }

    public void registerMenuItemListener(ICVSApplicationMessageMenuItemListener l){
        if(listeners == null)
            listeners = new CVSVector();

        if(l != null)
            listeners.addItem(l);
    }

    public String toString() {
        return null;
    }

}

I can see the message in the messages list (opened from home notification icon), but cannot open it. If I do the following it works, but then I have no callback when the message it's opened:

//messagefolderRegistry.registerMessageMenuItems(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, new ApplicationMenuItem[]{menuItem});
Alexandru Circus
  • 5,478
  • 7
  • 52
  • 89
  • Could you check that no exceptions happen in your run code. I would even say that using listeners is wrong because whenever you registered menu item it runs in context on messages application not yours – Eugen Martynov Dec 23 '12 at 10:29
  • no exception was encountered. Do you have another suggestion that I can use to find when a message thrown by my app is opened? – Alexandru Circus Dec 24 '12 at 05:02
  • Sorry, I don't have anything to suggest more. Ask on bb dev forum please – Eugen Martynov Dec 24 '12 at 12:33

1 Answers1

0

As I understand you don't see system "Message preview" screen any more. I have same problem. Seems when you register menu item it completely overrides open action. I checked Message List Demo and found that they open custom preview message screen inside ApplicationMenuItem's run() method. As I didn't found any way to open system "Message preview" screen with my message I'm going to implement custom screen also.

Yuriy
  • 1,466
  • 2
  • 14
  • 30
  • Thanks for your share. I saw that they opened custom screen from the run method and until now this looks the only way. I will make a screen to paint the messages custom. Also I found no way to invoke the "Message Preview" app, screen, etc. Thanks. – Alexandru Circus Jan 07 '13 at 12:43