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>
{
@Override
protected Integer doInBackground(Void... params) {
//do some stuff that returns an Integer.
}
@Override
protected void onPreExecute() {
showDialog(CONNECTION_DIALOG);
}
@Override
protected void onPostExecute(Integer result) {
if (connectionDialog.isShowing()) {
dismissDialog(CONNECTION_DIALOG);
}
}
}
@Override
protected 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en