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
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800
Accepted Solution

Background process with a timer

Hi All,

 

i have written a thread which does some background implementations like socket connection, read from bluetooth.etc. Now i want this thread to run every few seconds and it will return a result which is displayed on the UI.

 

To run the thread for every few seconds, i can use the TimerTask API. But will this work  when my application is currently not on foreground, and someother application is used. If not, could someone please tell me what is the alternative.(Something like AsyncTask from Android and a Handler to run every few seconds)

and how would i return the result from the background thread to the UI?

Anything else i need to handle in the process?

BR,
Supriya
Please use plain text.
Regular Contributor
nag
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800

Re: Background process with a timer

i really wonder if anybody solve this issue...................

even i am searching for the solution since 1 month ,to work with 2 tasks at a time in blackberry...eventhough we have threads concept in java we are unable to implement in the blackberry....any help appreciated

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Please use plain text.
Developer
simon_hain
Posts: 16,137
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Background process with a timer

sure, you can use timertask this way. spawn a new thread in it to avoid blocking the timer execution.
on older OS you have to use a threadpool to avoid a toomanythreads exeception.

you can also use realtimelistener for a different approach.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800

Re: Background process with a timer

Hi Simon,

 

how could i implement a realtime listener?? i really did not understand you on this point??

BR,
Supriya
Please use plain text.
Developer
simon_hain
Posts: 16,137
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Background process with a timer

http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/system/RealtimeClockListener.h...

Note that the system actually invokes this method each minute.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800

Re: Background process with a timer

thanks alot Simon for all the help,

 

I used the TimerTask api and in it  a thread to do the background process.

 

After every few seconds the background process is executed and returns the data. But everytime i receive data its not getting immediatley displayed on the UI.

 

How can i display it parallely ?

BR,
Supriya
Please use plain text.
Developer
hemak
Posts: 97
Registered: ‎10-06-2009
My Device: Not Specified

Re: Background process with a timer

check invokeAndWait method in Application/UiApplication class
Please use plain text.
Regular Contributor
supriya_dinakaran
Posts: 53
Registered: ‎06-29-2011
My Device: Blackberry 9800

Re: Background process with a timer

Thanks hemak, i used the UiApplication.getUiApplication().invokeLater

and it worked
BR,
Supriya
Please use plain text.