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
karthikpalanivelu
Posts: 63
Registered: ‎10-19-2012
My Device: BlackBerry PlayBook
My Carrier: Koodo

Blackberry class equivalent to Android's AsyncTask?

Hi,

 

I searched a lot on this. But couldn't get a solution.

 

My requirement is to have a thread (alive all the time) that maintains a socket connection between blackberry device and a server and exchanges commands. Similar to request and response. My problem is that I need to have this thread running in the background all the time and keep the UI available to user. So, When there is a command from the server, this thread parses it and updates the UI and also if there's an action from the blackberry user, it sends it to the server and server in turn handles it.

 

I developed the same application in Android using AsyncTask and it's working excellent. But in Blackberry, as there's no such class, I used invokeLater() option. The communication works fine between Server and the BB device. But UI is frozen in BlackBerry.

 

Anyone have any idea how to get this right, please reply back.

 

Thanks in advance.

Karthik

--------------------------------------------------------------------------
Karthik Palanivelu
Founder and Developer
Andhamil
Follow Us. We are Everywhere.
Facebook, Google+ and Twitter
----------------------------------------------------------------------------
Please use plain text.
Developer
mreed
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Blackberry class equivalent to Android's AsyncTask?

Use a Thread to do the network... work. To update the UI use a synchronized block using Application.getEventLock(). invokeLater() runs on the UI thread, so if you were doing network code in there, you were stalling the app.

Please use plain text.
Regular Contributor
karthikpalanivelu
Posts: 63
Registered: ‎10-19-2012
My Device: BlackBerry PlayBook
My Carrier: Koodo

Re: Blackberry class equivalent to Android's AsyncTask?

Hi mreed,

 

Thanks. I am already doing network stuff on a separate thread. But I dont understand what you saying about UI. My concern is not just to update the UI from network thread but also to let the user play with the UI even though network connection is alive on a separate thread. can you please tell me ur solution in brief?

 

Thanks,

Karthik

--------------------------------------------------------------------------
Karthik Palanivelu
Founder and Developer
Andhamil
Follow Us. We are Everywhere.
Facebook, Google+ and Twitter
----------------------------------------------------------------------------
Please use plain text.
Developer
simon_hain
Posts: 16,044
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Blackberry class equivalent to Android's AsyncTask?

if you execute networking on a separate thread the UI should not be frozen (unless the cpu is at max load).
maybe you can give some meaningful code snippets like starting the thread and how it interacts with the UI?
----------------------------------------------------------
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.