UI Access in Android Development
I'm working on an application 开发者_运维百科for my Android device (Honeycomb) and I've ran into an issue I'm having difficulty solving. The application will have a large multi-lined text field in the center of the screen that will be populated by a background thread which is communicating with a remote server over sockets.
So i've looked into AsyncTask and its very close to what I need, except for the fact that I'd need to be updating the UI in the doInBackground. I need to maintain the socket connection while the program runs and as new messages are received, populate them onto the UI.
While messages are coming in and being populated into the UI, the user has the option of sending messages out on another socket.
Any suggestions on how to do this? Using the onPostExecute(...) method just won't do exactly what I need ... and if I use a loop in the doInBackground, I have no way of updating the UI.
I'm sure I'm missing something rather obvious. Any suggestions?
Thanks so much!!
AsyncTask has the functionality in place to update the UI. From doInBackground call publishProgress, then onProgressUpdate will be called on the UI thread to let you update it.
精彩评论