Android ASyncTask not displaying dialog in onPreExecute() when using get() to return value

Go To StackoverFlow.com

1

I need to return a value to the main thread from an ASyncTask, so I have used the get() method so that the main thread waits until the background thread is run.

time = mFetchServerDate.execute().get();

However in my ASyncTask I have a progress dialog opening in the onPreExecute() method which works as expected when I don't use the get() but when I add it back in it just hangs the app, shows the dialog for a fraction of a second then goes back to the main thread.

@Override 
protected void onPreExecute(){
   super.onPreExecute();
   pd = ProgressDialog.show(mContext, "", "", true, false);
}
2012-04-04 08:25
by Carrie Hall
how can it be shown when you pause the main thread which is responsible for showing dialog.. - ngesh 2012-04-04 08:26
please dont use get() on the UI thread. You could make the progress dialog not cancelable or disable ui elements until the asyncTask finishes - Renard 2012-04-04 08:28
Fair enough, I ended up not needed to get the date from the server anywa - Carrie Hall 2012-05-25 08:03


0

i am not sure its has not work if you have used get() method for asyncTask .

anyway you can user this.runOnUiThread(action) ; when you need to update UI in thread like AsyncTaks .

2012-04-04 08:57
by dharam
Ads