i have a class derived from AsyncTask and i initialize it in my
activity. Now i m facing two problems...
1. I want to send result back to my activity and execute a chunk of
code in my activty on onPostExecute(Object result) event. (i tried
handler but its not working)
2. I want to execute asynctask multiple times.
Please suggest me some better solution or a fix to this...
thanx in advance
ACTIVITY CODE:
StudentTask st = new StudentTask(getThis());
st.execute(new Object[] {StudentTask.Task.AUTH, null,
userName,
password);
CLASS CODE:
public class StudentTask extends AsyncTask {
private Context context;
private ProgressDialog pd;
public static enum Task {
SYNCRONIZE, AUTH, ACTIVATE
}
public StudentTask(Context context) {
super();
this.context = context;
}
@Override
protected void onPreExecute() {
pd = ProgressDialog.show(context, "Please wait", "Starting");
}
@Override
protected Object doInBackground(Object... params) {
Object result = null;
Task t = (Task) params[0];
switch (t) {
case AUTH:
if (this.authenticateStudent(params[1].toString(),
params[2].toString()).IsSuccessFul()) {
result = true;
} else {
result = false;
}
break;
case SYNCRONIZE:
result = this.synchronize(null, null);
break;
default:
break;
}
return result;
}
@Override
protected void onProgressUpdate(Object... values) {
pd.setMessage(values[0].toString());
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(Object result) {
pd.dismiss();
// Send this result back to activity and execute some code there
e.g. launch next activity or display error
super.onPostExecute(result);
}
--
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