Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 4
Registered: ‎01-16-2010
My Device: 7250
My Carrier: Bell
Accepted Solution

Dialog.show() method doesn't work in folderListener event

[ Edited ]

Hi there,

 

I have a background running application (No UI). A feature of this application is listen the email folder to popup a dialog to prompt the user when there is a new email is sent out. Following code works well when I run it on BlackBerry OS 6.0.0.141. It pops up a dialog to ask if the user would like to use my application's feature:

 

public void messagesAdded(FolderEvent e){

    if( e.getMessage().isInbound() == true ) {

        return;

    }

    Dialog dlg = new Dialog(Dialog.D_YES_NO, "Would you like ...?", Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 0L);

    m_msgboxListener = new MessageBoxClosedListener(msg); dlg.setDialogClosedListener(m_msgboxListener);

    dlg.show();

} ...

    But when I switch to BlackBerry OS 6.0.0.534, there is no dialog showing up. The odd thing is, I have a similar feature works fine. This feature listens to the phone call event. Following is the code:

 ...

 

public void callDisconnected(int callId) {

    if(m_phoneCall != null ){

        Dialog dlg = new Dialog(Dialog.D_YES_NO, "Would you like...?", Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 0L);

        m_msgboxListener = new MessageBoxClosedListener(m_phoneCall);

        dlg.setDialogClosedListener(m_msgboxListener); dlg.show();

    }

}

...

 

    I have tried the ways below to resolve this issue, but all failed:

 

1. I tried to get EventLock in messagesAdded() method by using Application.getEventLock(). It didn't work.

 

public void messagesAdded(FolderEvent e){

...

    Dialog dlg = new Dialog(Dialog.D_YES_NO, "Would you like...?", Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 0L);

    m_msgboxListener = new MessageBoxClosedListener(msg);

    dlg.setDialogClosedListener(m_msgboxListener);

    synchronized(Application.getEventLock()) {

        dlg.show();

    }

}

 ...

2. I sent a global event to the application itself from messagesAdded() method and use Application.invokeLater() in eventOccurred() to display the dialog. But no dialog pops up.

 

public void eventOccurred(long guid, int data0, int data1, Object obj0, Object obj1) {

    if ( guid == GUID_MAEVENT_EMAIL_IS_SENT) {

        invokeLater( new Runnable() {

            public void run() {

                Dialog dlg = new Dialog(Dialog.D_YES_NO, "Would you like...?", Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 0L);

                m_msgboxListener = new MessageBoxClosedListener(msg);

                dlg.setDialogClosedListener(m_msgboxListener);

                dlg.show();

            });

        }

}

 

3. I sent a global event to the application itself from messagesAdded() method and use Application.getEventLock() to get EventLock to display the dialog. But still no dialog pops up.

 

public void eventOccurred(long guid, int data0, int data1, Object obj0, Object obj1) {

    if ( guid == GUID_MAEVENT_EMAIL_IS_SENT) {

        Message msg = (Message)obj0;

        Dialog dlg = new Dialog(Dialog.D_YES_NO, "Would you like...?", Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 0L);

        m_msgboxListener = new MessageBoxClosedListener(msg); dlg.setDialogClosedListener(m_msgboxListener);

        synchronized(Application.getEventLock()) {

            dlg.show();

         }

    }

}

 

4. I Changed the show() to doModel(). It didn't work.

 

Is this a bug of BlackBerry OS between 6.0.0.141 to 6.0.0.534?

 

Please help.

BlackBerry Development Advisor
Posts: 15,302
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Dialog.show() method doesn't work in folderListener event

This approach should work.

 

Alert a BlackBerry smartphone user from a Background application

http://supportforums.blackberry.com/t5/Java-Development/Alert-a-BlackBerry-smartphone-user-from-a-Ba...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 4
Registered: ‎01-16-2010
My Device: 7250
My Carrier: Bell

Re: Dialog.show() method doesn't work in folderListener event

Thanks Mark,

 

This is very helpful. The problem is resolved. There are 3 key points:

 

1. Main class should extend UiApplication class.

2. The folder event process must send a global event to mail class.

3. Get event lock and use UiEngine to push dialog rather than call show() method.

....

        Message msg = (Message) data;
       
        synchronized(UiApplication.getUiApplication().getEventLock()) {
            UiEngine ui = Ui.getUiEngine();
            Dialog dlg = new Dialog(Dialog.D_YES_NO, "Copy Email?", Dialog.NO, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 0L);
            m_msgboxListener = new MessageBoxClosedListener(msg);
            dlg.setDialogClosedListener(m_msgboxListener);           
           
            Screen screen = (Screen) dlg;
            ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
        }