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: 34
Registered: ‎08-11-2011
My Device: BlackBerry Bold
My Carrier: Axis
Accepted Solution

Performing Network Related Tasks on After Startup

Hi, I want to perform network related tasks such as downloading content from the web service everytime my application starts, before the user can use it. The problem is the network isn't ready yet when the application starts in autorun mode (during the BlackBerry device's startup process) so I can't request content from the web service.

I was wondering, is it possible to halt the execution of the program until the device's network coverage is sufficient?

Thanks.
Contributor
Posts: 10
Registered: ‎12-26-2011
My Device: 9000
My Carrier: Vodafone IN

Re: Performing Network Related Tasks on After Startup

Attach RadioStatusListener or CoverageStatusListener (or both) depending on what you are trying to accomplish. Enter the event loop in the app code so that the application does not exit. Prepare the state of your application based on the callbacks you receive on the listeners. Push your screen on to the display stack when the app is ready (make sure to use invokeLater() to push the screen if you are doing that from a non-event thread). That should do it.

Developer
Posts: 34
Registered: ‎08-11-2011
My Device: BlackBerry Bold
My Carrier: Axis

Re: Performing Network Related Tasks on After Startup

I believe what you suggested should work. But I don't understand what you mean by "enter the event loop". Could you elaborate?

My main concern is that the device will freeze if I use somthing like invokeAndWait to halt the execution of my code.

Thanks in advance.
Contributor
Posts: 10
Registered: ‎12-26-2011
My Device: 9000
My Carrier: Vodafone IN

Re: Performing Network Related Tasks on After Startup

[ Edited ]

Pseudocode:

 

MyApp -> UiApplication, Runnable
{
    main()
    {
        MyApp  app = new MyApp() ;

        new Thread(app).start() ;
        app.enterEventDispatcher() ;
    }

    run()
    {
        prepareAppWithYourLogic() ;
        invokeLater(new Screen()) ;
    }
}

Screen -> MainScreen, Runnable
{
    run()
    {
        UiApplication.getApplication().pushScreen(this) ;
    }
}

I am not sure whether the event loop will block or exit - we have not pushed a screen on the display stack at that point in time. If it exits, make the thread wait() instead and notify() from the spawned thread when initialization is done. The main thread can then push the screen on the stack and enter the event loop.

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: Performing Network Related Tasks on After Startup