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
New Developer
Posts: 58
Registered: ‎08-05-2009
My Device: Not Specified
Accepted Solution

Bachground thread for Bluetooth Serial Port Communication

Hello ,

 

I want to make an application which should be as a background thread run after that BB has been turned on.

 

I have tried something:

 

1.  I have used BluetoothSerialPortListener and made it as a normal application. After i have chosen the menuitem, it starts to listen for the bluetooth serial port. When data has arrived by port, it takes the data and write a response to the sender. Then it take the value out and show it on the display, where i used a MainScreen class object. But, after a value has been displayed, it could not display the second arrived value. I have tried, which fist pop the old Screen and then puschup the new Screen. But it doesn't work. How can make it, when new value arrive, they can be diaplayed on the display?

2.Then i have made the BluetoothSerialPortListener in a thread and used autostart flag such as:

public static void main(String[] args)
    {       
        if(args != null && args.length > 0 )
        {
            if(args[0].equals("autostartup"))   
            {
                // When device starts we want to start the SycareBluetoothPortListener thread
             
                //sycare_synergy ss = new sycare_synergy();
             } 
        }

 

This time the Listner should only take the arrived data and then send a response to the sender. But after download, BB showed always that it could not generate a new object of the thread class and the thread could not be started.

 

Could anybody tell me, how can i fix it and make it possible, that after every new start of BB, the bluetooth serial port can always in background the arrived data receive and diaplay it automated after the data has arrived?

 

 

Thank you sincerely in advanced and  merry chiristmas!

 

 

monternet

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

Re: Background thread for Bluetooth Serial Port Communication

1. Updating the UI.

 

What you are trying to do is possible.  In fact you do not need to replace the screen, you should be able to just update a data Field on the current Screen.  As an example of a background Thread updating the UI, please review the httpdemo code.

 

2. Background Thread

 

When you say things like:

"that it could not generate a new object of the thread class"

it would be much better if you could quote exactly what the Blackberry did.  In this case I presume it generated an Exception, so The Exception and the detail message associated with that Exception should be included when you report a problem like this.

 

Anyway, it is possible to set up a Background task in the way that you require.  Search the Knowlegebase for articles that talk about Background Applications and auto-start applications and displaying UI updates from Background task.  There are some confusing bits to this process, so there is a bit to get your head round, but I think it is all in the KB articles. 

New Developer
Posts: 58
Registered: ‎08-05-2009
My Device: Not Specified

Re: Background thread for Bluetooth Serial Port Communication

Thank you very much peter_strange!

 

You have given me the confidence, that it can be made!

 

Now i will search some aritcels and try it. I think, i will show you the INFO later that the BB gives me.

 

 

Thanks again and wish you a merry christmas!

 

monternet

New Developer
Posts: 58
Registered: ‎08-05-2009
My Device: Not Specified

Re: Background thread for Bluetooth Serial Port Communication

Hi peter,

 

i have seen the HttpDemo Project. In that project a RichTextField has been directly added to MainScreen. Update display can be realised through the function setText( ).

But in my project, i need a special display so i have used a Manager object and a Field object to display the special layout what i need.  So setText( )  can not directly work in my case.

 

Could you or someone give me any tipps?

 

 

Thanks in advanced!