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
Developer
Posts: 69
Registered: ‎10-27-2008
My Device: Not Specified
Accepted Solution

Possible bug in OS 5.0 with SendListener?

I've come up with an issue where a SendListener in OS 5.0, when trying to display a modal screen, is causing the unit to freeze and not display the popup screen.  I've been able to create a test class to demonstrate it:

 

 

public class TestSendListener implements SendListener
{
    public boolean sendMessage( Message arg0 )
    {
        String dialogMessage = "Would you like to send the message?";
        if ( askYesNo( dialogMessage ) == 0 )
        {
            return true;
        }

        return false;
    }

    private int askYesNo( String message )
    {
        return askYesNo( message,
                         true );
    }

    private int askYesNo( String message,
                          boolean yesDefault )
    {
        Object[] choices = new Object[] { "Yes", "No" };

        return ask( message,
                    choices,
                    yesDefault ? 0 : 1 );
    }

    private int ask( final String message,
                     final Object[] choices,
                     final int defaultChoice )
    {
        final Dialog dialog = new Dialog(
                                          message,
                                          choices,
                                          null,
                                          defaultChoice,
                                          Bitmap
                                              .getPredefinedBitmap( Bitmap.QUESTION ) );

        synchronized ( Application.getEventLock() )
        {
            Application.getApplication().invokeAndWait( new Runnable()
            {

                public void run()
                {
                    UiApplication.getUiApplication().pushModalScreen( dialog );
                }

            } );
        }

        return dialog.getSelectedValue();
    }
}

 

 

Has anyone run into this issue at all?  This sample class above works on all 4.x OS versions, but won't on any of the 5.0.  As well, what's strange, is that this same method of displaying the popup dialog *works* on an ViewListener.  I"m just looking either for a workaround (if it's a bug) or for someone to tell me I'm doing it completely wrong.  :smileywink:

 

 

Thanks

Matty

 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Possible bug in OS 5.0 with SendListener?

Hmm, first off I might be missing something but I fail to see how this is a bug with SendListener. Does it not get called? arg0 = null? Etc.

 

The place where I would see an issue is in the ask function, you get the Application lock (which means the event thread won't run until you release the lock), then you call invokeAndWait which puts the Runnable on the stack for the event thead to process. If you havn't seen what I am getting at yet, the event thread isn't running yet you called a function that requires the event thread to run and process the event. The part I find odd is that you said this only occurs on 5.0, it should technically occur on all OSes.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
Posts: 69
Registered: ‎10-27-2008
My Device: Not Specified

Re: Possible bug in OS 5.0 with SendListener?

If I get rid of the synch block, it still works on all OSes except 5.0.  The reason I think it's a SendListener issue is because it works on all other places, except that one -- my thoughts about it are that it has a deadlock somewhere in the code executing SendListeners.

 

It's not about the 'ask' function, it's really about the fact that the SendListener isn't able to display *any* popup (Dialog, custom PopupScreen, etc.) with this simple example.  All this example is doing is popping up a Dialog to ask a Yes/No question, so that you can see that the result works and gets sent back to the SendListener caller ('true' to send the message, 'false' to halt it).  In OS 5.0, the Dialog never appears and the OS freezes while it waits for a response from sendMessage (which, is frozen waiting for the ability to put the Dialog on the screen and get an answer).

 

M

 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Possible bug in OS 5.0 with SendListener?

I see, it could be possible that some code "behind the scenes" in the OS is locking something that you need and it is causing the OS to freeze. I'm not exactly sure where to go from there, sorry.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
Posts: 69
Registered: ‎10-27-2008
My Device: Not Specified

Re: Possible bug in OS 5.0 with SendListener?

Yeah, that's my thought.  That's why I'm asking if anyone has had similar issues with 5.0, because I don't see how it just all of a sudden got broken in just one area (SendListener) and the rest of them work.

 

M

 

Please use plain text.
Developer
Posts: 69
Registered: ‎10-27-2008
My Device: Not Specified

Re: Possible bug in OS 5.0 with SendListener?

/bump for a response.

Please use plain text.
Administrator
MSohm
Posts: 14,296
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Possible bug in OS 5.0 with SendListener?

This should solve your issue:

 

How To - Display a PopupScreen from a SendListener
Article Number: DB-00668

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/How_To_...

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
Please use plain text.
Developer
Posts: 69
Registered: ‎10-27-2008
My Device: Not Specified

Re: Possible bug in OS 5.0 with SendListener?

Mark,

 

While I appreciate the link, it is did not solve my issue.  Here is my test class (formed from the information on the link):

 

 

public class SendListenerTestApp extends Application implements SendListener
{
    public static void main( String[] args )
    {
        SendListenerTestApp theApp = new SendListenerTestApp();
        theApp.enterEventDispatcher();
    }

    public SendListenerTestApp()
    {
        // Add the listener for encrypting outgoing messages,
        // one for each mail instance in the service book
        ServiceRecord[] records = ServiceBook.getSB().getRecords();
        if ( records != null )
        {
            Vector addedAccounts = new Vector();
            for ( int i = 0; i < records.length; i++ )
            {
                try
                {
                    ServiceRecord currentRecord = records[ i ];
                    if ( currentRecord != null
                         && currentRecord.getCid().equalsIgnoreCase( "CMIME" ) )
                    {
                        ServiceConfiguration currentConfiguration = new ServiceConfiguration(
                                                                                              currentRecord );
                        if ( !addedAccounts.contains( currentConfiguration
                            .getName() ) )
                        {
                            Store currentStore = Session
                                .getInstance( currentConfiguration ).getStore();
                            currentStore.addSendListener( this );

                            addedAccounts.addElement( currentConfiguration
                                .getName() );
                        }
                    }
                }
                catch ( Exception e )
                {
                    // Ignore it and try the next one
                }
            }
        }
    }

    public boolean sendMessage( Message msg )
    {
        Dialog myDialog = new Dialog(
                                      Dialog.D_OK,
                                      "This is a Message from a SendListener",
                                      Dialog.OK,
                                      Bitmap
                                          .getPredefinedBitmap( Bitmap.EXCLAMATION ),
                                      Dialog.GLOBAL_STATUS )
        {
            // Override inHolster to prevent the Dialog from being dismissed
            // when a user holsters their BlackBerry. This can
            // cause a deadlock situation as the Messages
            // application tries to save a draft of the message
            // while the SendListener is waiting for the user to
            // dismiss the Dialog.
            public void inHolster()
            {

            }
        };

        // Obtain the application triggering the SendListener.
        Application currentApp = Application.getApplication();

        // Detect if the application is a UiApplication (has a GUI).
        if ( currentApp instanceof UiApplication )
        {
            // The sendMessage method is being triggered from
            // within a UiApplication.
            // Display the dialog using is show method.
            myDialog.show();
        }
        else
        {
            // The sendMessage method is being triggered from
            // within an application (background application).
            Ui.getUiEngine().pushGlobalScreen( myDialog,
                                               1,
                                               UiEngine.GLOBAL_MODAL );
        }

        return true;
    }
}

 

 

The constructor and main methods just set the application up to attach to each CMIME (email) record on the device, adding this SendListener to it.  The sendMessage method is from the link you provided, unedited.

 

When it is compiled with JDE 4.2.1 (required, because that version of pushGlobalScreen was only introduced in 4.2.0), it runs perfectly in all OS versions from 4.2.1 to 4.7.x.  However, in the OS 5.0 simulators (I'm using a 9700 at 5.0.0.228 and 9500 at 5.0.0.252), this application causes an IllegalStateException due to accessing the UI engine without the lock.

 

Any other suggestions on how to get around this OS 5.0 issue?

M

 

 

Please use plain text.
Developer
Posts: 69
Registered: ‎10-27-2008
My Device: Not Specified

Re: Possible bug in OS 5.0 with SendListener?

/bump

Please use plain text.
Developer
Posts: 69
Registered: ‎10-27-2008
My Device: Not Specified

Re: Possible bug in OS 5.0 with SendListener?

/bump

Please use plain text.