views:

72

answers:

2

I would like to have a Toast Message appear while my app is downloading information but even if I put it before my code it doesn't appear until after the download has completed. Putting my code in a separate thread causes many headaches but putting toast in a separate thread doesn't work either. Is there anyway I can have this Toast message come up before this or am I just going to have to work through the headaches?

+3  A: 

You should be putting asynchronous downloads in a separate thread anyway, so as to not disable the main thread's UI. When you call a blocking I/O method, the UI will not respond.

Check out this documentation on Handling Expensive Operation in the UI Thread.

magaio
I know, but Java has a paintImmediatly method that you can use if you need to paint something even if the UI thread is being blocked.
Mitchell
@Mitchell: The problem is that if the UI thread blocks for too long (I believe 5 seconds), Android assumes that your app is frozen and displays the ANR dialog to the user. You really don't want that.
Quartz
I didn't know that was what was causing that. So I guess the point is moot. Thanks everyone!
Mitchell
+1  A: 

As magaio already said you should use another thread for downloading stuff. My two cents:

  • use progress dialog instead of Toast so User can actually see the process
  • Use AsyncTask for download to update progress so user can actually see the progress
Nikolay Ivanov