Skip to content Skip to sidebar Skip to footer

Android, Async And Progress Dialogs

I have following piece of code: public class SomeActivity extends Activity { Context context; List menuItems; public void importList(View v) {

Solution 1:

I think that it has sth to do with these contexts

Not at all. Also, when sending Context from an Activity you don't need to create a variable. Simply use this or ActivityName.this.

 MyAsyncTask task = new MyAsyncTask(this);

But when I uncomment it, ProgressDialog appears AFTER the task is finished, and value returned. Why is that?

Calling get() blocks the UI, this is why you don't see the progress until it is done. You don't need to call this. The point of onProgressUpdate() is so the background thread (doInBackground()) can call it to update the UI since doInBackground() doesn't run on the UI.

Remove that line from your code and never look at it again. If there is a reason that you think you need it then please explain and we can help you find a better way.

Edit

See this SO answer on updating when the task is finished


Post a Comment for "Android, Async And Progress Dialogs"