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: 27
Registered: ‎07-17-2008
My Device: Not Specified

Dialog.ask() in background thread crashes app on Bold simulator

The following piece of code is run from a background thread which runs whilst our application's splash screen is being displayed to the user.  This code is executed once all background processing has been completed.  As part of this process I display a dialog to the user to confirm an action which then determines what happens next. 

 

When running this code on a 4.2 device simulator it works perfectly, but on the BlackBerry Bold simulator, selecting either Yes or No on the dialog crashes the app - if an exception is being thrown at this point, the catch statement is certainly not executed.  I have highlighted the offending piece of code in red.

 

I have tested the Dialog.ask() method from the main thread, which works fine, so it seems that the problem is due to it being in a background thread.

 

Does anybody have any ideas why this might be the case?

 

Thanks,

 

Joanna

 

        try
        {
            synchronized(UiApplication.getEventLock())
            {
                // We want to remove this screen from the display stack
                // as we don't want to let the user see it when exiting the app
                UiApplication.getUiApplication().popScreen(this);        
                   
                if (ApplicationManager.getApplicationMode() == ApplicationMode.OFFLINE)
                {
                    Application.getApplication().invokeLater
                        (
                            new Runnable()
                            {
                                public void run()
                                {
                                    if (CoverageInfo.getCoverageStatus() == CoverageInfo.COVERAGE_NONE || Dialog.ask(Dialog.D_YES_NO, _rbResources.getString(MobileResource.MSG_OFFLINE), Dialog.NO) == Dialog.YES)
                                    {
                                        // Push the offline menu screen onto the display stack
                                        UiApplication.getUiApplication().pushScreen(new ScrOfflineMenu());
                                    }
                                    else
                                    {
                                        // Flush all the logs
                                        ActivityLog.flushLog();
                                        LinkedResourceLog.flushLog();
                                        SchemaLog.flushLog();                                       
                                        // Reset the application mode
                                        ApplicationManager.setApplicationMode(ApplicationMode.ONLINE);                                       
                                        // Push the login screen onto the display stack
                                        UiApplication.getUiApplication().pushScreen(new ScrLogin(aoUser, aoSubscription));
                                    }
                                }
                            }
                        );                   
                }
                else
                {  
                    // Push the login screen onto the display stack
                    UiApplication.getUiApplication().pushScreen(new ScrLogin(aoUser, aoSubscription));
                }       
            }
        }
        catch (Exception ex)
        {
            ApplicationManager.displayErrorDialog(ex);
        }

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

Re: Dialog.ask() in background thread crashes app on Bold simulator

Please have a look at this developer knowledge base article.

 

How To - Alert a user from a Background application
Article Number: DB-00407

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800608/...

 

You are calling a number of methods while sychronizing on the main event thread (the flushlog methods).  Is there a lot of processing in these methods?  An application should hold onto the event thread for as little time as possible.

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
Developer
Posts: 27
Registered: ‎07-17-2008
My Device: Not Specified

Re: Dialog.ask() in background thread crashes app on Bold simulator

The flushlog methods are never executed.  The application crashes once a button is clicked on the dialog and the next line of code is not reached. 

 

We have never had any problems with this code on earlier simulators used (mainly 4.2.1 and 4.2.2 versions) and the devices we are currently testing our application on (pre-9000 series). 

 

Joanna

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

Re: Dialog.ask() in background thread crashes app on Bold simulator

My suggestion to move these methods outside of this code block was a best practice suggestion to increase the stability of your application, not a solution to the Dialog.ask issue.  This can happen if an application does heavy processing on the main event thread.

 

Support - Process [ApplicationName] killed due to message queue overflow
Article Number: DB-00401

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/Support...

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
Developer
Posts: 27
Registered: ‎07-17-2008
My Device: Not Specified

Re: Dialog.ask() in background thread crashes app on Bold simulator

Thanks for your observations about best practice.  I will take these on board.

 

I have now created a new project which does the same thing, but without any processing occuring in the background thread.  The application still crashes after the dialog is responded to by the user selecting one of the buttons.  The next line of code is never executed.

 

Any suggestions to resolve this problem would be appreciated.

 

Regards,

 

Joanna

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

Re: Dialog.ask() in background thread crashes app on Bold simulator

Dialog.ask is not supported from a background application.  Please see the link in my previous post for a link to a code sample on how to display an alert from a background application.
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
Developer
Posts: 27
Registered: ‎07-17-2008
My Device: Not Specified

Re: Dialog.ask() in background thread crashes app on Bold simulator

The application isn't a background application.  It's a regular foreground application which happens to need to display a dialog from a background thread which is run as part of the application.

 

If this is the only way to do this, then how do I then perform differing actions within the application depending on the option selected by the user e.g.

if (dialogResult = Yes) pushScreen(screenA)

else pushScreen(screenB)

Can you give me a code sample?

 

Thanks

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

Re: Dialog.ask() in background thread crashes app on Bold simulator

What exception is being thrown?  Note that only the main event thread is able to update the GUI of an application.

 

How to - Update a screen on the Main Event Thread
Article Number: DB-00136

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/...

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
Developer
Posts: 27
Registered: ‎07-17-2008
My Device: Not Specified

Re: Dialog.ask() in background thread crashes app on Bold simulator

There is no exception being thrown.  Neither the next line of code or the catch block is ever executed.  The application just exits and returns the user to the downloads ribbon screen.
BlackBerry Development Advisor
Posts: 15,136
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Dialog.ask() in background thread crashes app on Bold simulator

Does this occur if you wrap the Dialog.ask call in the sample code block in the article from my previous post? 

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