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);
}
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 .