10-19-2012 04:38 PM
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.
10-19-2012 07:24 PM
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.
10-22-2012 09:06 AM
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?
10-22-2012 09:23 AM