I am targeting Android 4.0 and am communicating with a telemetry device using TCP/IP. Android 4.0 forces all networking to be done in a separate thread. First I open a socket, then I contact the device and download some information all from a separate thread. At this point I want to display a progress dialong to show the progress of downloading more detailed information. My problem is that I cannot show the progress dialog from anywhere but the main UI. But, I do not know when I have reached the point in the other thread where I am ready to display the progress dialog. Is there some way I can check for this from the main UI without tying up the system?
I am targeting Android 4.0 and am communicating with a telemetry device using TCP/IP.
Share
To trigger the dialog on your main ui, you need to use ‘context.runOnUiThread()’ where context is the reference to your display activity. It’s also worth looking into using an AsyncTask.
Here is an android blog post that explains everything in detail: http://android-developers.blogspot.ca/2009/05/painless-threading.html
As an aside, you can also just start displaying a indeterminate progress dialog from the start, so the user is never waiting without visual feedback, then switch to the determinate when you know the download details.