result = connectionTask.execute().get();
Did you read the documentation for the get() method (http://developer.android.com/reference/android/os/AsyncTask.html#get%28%29)? It says it causes the calling thread to wait for the computation to complete... Guess what? The calling thread is the UI thread, which is what will be used to display the dialog.
Change it to: connectionTask.execute();
And then handle your result stuff in the onPostExecute() method...
Hope that helps...
Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware
On Fri, Apr 6, 2012 at 7:30 PM, tete <ingenieria.stv@gmail.com> wrote:
Hello people,This is my first post so, i hope to do it well.I'm develop an application on Andoid 2.2 Api 8 and i can't find why the ProgressDialog doen't show when I'm calling it from an AsyncTask.This is the part of code that attemps to show the progress dialog:private static final int CONNECTION_DIALOG = 1;private ProgressDialog connectionDialog;private AndroidPvmRivarosaActivity activity;public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);activity = this;Button btnAceptar = (Button) findViewById(R.id.btnAceptar);btnAceptar.setOnClickListener(new OnClickListener() {public void onClick(View v) {...connectionTask = new ConnectionAsyncTask();int result = -1;try {result = connectionTask.execute().get();} catch (InterruptedException e) {e.printStackTrace();} catch (ExecutionException e) {e.printStackTrace();}...}});}--private class ConnectionAsyncTask extends AsyncTask<Void, Void, Integer>{@Overrideprotected Integer doInBackground(Void... params) {//do some stuff that returns an Integer.}@Overrideprotected void onPreExecute() {showDialog(CONNECTION_DIALOG);}@Overrideprotected void onPostExecute(Integer result) {if (connectionDialog.isShowing()) {dismissDialog(CONNECTION_DIALOG);}}}@Overrideprotected Dialog onCreateDialog(int id) {if (id == CONNECTION_DIALOG) {connectionDialog = new ProgressDialog(activity);connectionDialog.setMessage("Conectando...");connectionDialog.setCancelable(true);return connectionDialog;}return super.onCreateDialog(id);}
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
No comments:
Post a Comment