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
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

How do i make a background thread.

I am a novice, so thank you for seeking to help me

 

Well I actually know what a thread is, but I have no clue as how to make a background thread. I would love a coded explanation to clear my doubts. For example a timer running in an aplication would be a good slot of code to use.

 

But any-who I really need to learn how to make a background thread. And I really don't understand much of the complicated terms, so anything simple that my little brain can grasp would be nice.

_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Highlighted
Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How do i make a background thread.

Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: How do i make a background thread.

Ok those are fine, but all I want is a simple layout of a thread and it's implementation. In the links you sent me..the focus is on how to get the timers to work. I would love just a template perhaps for creating threads.
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How do i make a background thread.

Hi,

  ok ill give here..

 You can create threads in two types.

(I) From any method call this

 

                new Thread(){
                    public void run(){
                        callThread();
                    }
                }.start();

 

 and called function should be like this

 private coid callThread(){

       try{
            UiApplication.getUiApplication().invokeLater(new Runnable(){
                public void run(){
                  //you have to write each executable item inside this otherwise it wont execute.                   

                }
            });

           //condition statement you can  write outside like this

          if(some Condition){

                 UiApplication.getUiApplication().invokeLater(new Runnable(){
                      public void run(){
                         //you have to write each executable item inside this otherwise it wont execute.                   

                      }
                 });

           }

        }catch(Exception e){}

 }

 

 

(II)This is class extending thread

 

public class threadclass extends Thread
{                     
        public void run()                      
        {            

               //here you can write the code to run
        }
}

 

Just call this class like this

new threadclass ().start();

 

Thanks & Regards

             pp


Super Contributor
Posts: 278
Registered: ‎11-04-2010
My Device: 4.5 and above
My Carrier: none

Re: How do i make a background thread.

sorry its private void callThread()
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How do i make a background thread.

Can I just clarify something here.

 

The only situation in which you need to have something like:

 

           UiApplication.getUiApplication().invokeLater(new Runnable(){
                public void run(){
                  //you have to write each executable item inside this otherwise it wont execute.                   

                }
            });

 

in your background Thread processing, is when you want that processing to update the User Interface.  If the background processing just does something like connect and download some data, then the code to do that should not be placed inside an invokeLater. 

 

Personally I very very seldom have 'invokeLater' or any other method of updating the Ui, in a Thread.  Instead I will have a screen that manages to Ui, initiates the Thread, and has itself as a Listener on the Thread, so that the Thread can pass back status information or whatever as needed.  If the Screen processing decides the information it has been given from the Thread requires a User Interface update, then it can dot he invokeLater.

 

Just my 2p worth....

Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: How do i make a background thread.

Huh pp, where should private void callThread go?
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: How do i make a background thread.

Oops, I see where now. Thanks
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.