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
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido
Accepted Solution

Starting a new Thread in activate() method

Hi,

 

When my app is launched, or resumes after a phone call etc... I would like to perform a few tasks in the activate() method. First I would like to start a new Thread to call a few web services, and when it's done I would like to update the UI.

 

I already tried to do this. I created a new class that extends Thread, in the run() method I placed all the relevant web service calling code, and in the activate() method of my main Thread I did:

 

MyThread myThread = new MyThread();

myThread.start();

 

But I noticed that nothing seems to be getting done. So I simplified my code by removing all the web service calls from the run() method and replacing it with a wait(500) method, followed by a method call to update UI (in this case it just creates a new ButtonField, just for testing purposes).

 

But the ButtonField never gets created.

 

The new thread doesn't seem to be starting at all.

 

Any suggestions??

 

Thanks a lot.

Developer
Posts: 543
Registered: ‎12-23-2010
My Device: Z10
My Carrier: Airtel

Re: Starting a new Thread in activate() method

Try with call back implementation, it will work!.

Thanks.
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: Starting a new Thread in activate() method

Thanks but I've tried that, nothing is working.

Developer
Posts: 455
Registered: ‎03-04-2011
My Device: Paper cup

Re: Starting a new Thread in activate() method

Have you tried setting breakpoints or using println to trace the execution?

 

Firstly, is activate() even being called?

 

Second, is run() being reached?

 

When the thread does the UI work, if you've got that in a synchronized block try an invokeLater block instead.

 

 

Highlighted
Super Contributor
Posts: 398
Registered: ‎01-12-2011
My Device: Q10
My Carrier: Fido

Re: Starting a new Thread in activate() method

Using invokeLater seemed to do it.

 

Thanks a million.