I have a simple app and I'm using the AsyncTask to test out a
background process, for clearness purposes I've opted to put my
AsyncTask in a separate class rather than in an inner class, which
where my problems begin, this is my AsyncTask
package org.tutorial.test101.tasks;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
public class LoginTask extends AsyncTask<String, String, String> {
Context ctx;
ProgressDialog pDialog;
public LoginTask(Context context){
super();
this.ctx=context;
}
@Override
protected String doInBackground(String... params) {
Log.i("LOGGER", "Starting...");
try{
Thread.sleep(8000);
}catch(InterruptedException e){
}
return null;
}
@Override
protected void onPostExecute(String result) {
Log.i("LOGGER", "Done...");
pDialog.dismiss();
//
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
pDialog=new ProgressDialog(ctx);
pDialog.setTitle("Login");
pDialog.setMessage("doing stuff..");
pDialog.show();
}
}
What I'd like is that once the task is complete, I do something in the
UI thread may be start another activity or even display a Toast saying
activity complete. I know I can't start a new Activity in the
onPostExecute() so I need to start it in the UI thread any idea how I
can do this? This is my Activity that starts the AsyncTask
package org.tutorial.test101.activities;
import org.tutorial.test101.tasks.LoginTask;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Test101 extends Activity{
private Button btnLogin;
private LoginTask mLoginTask;
private Context context=this;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnLogin=(Button)findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
if(mLoginTask==null){
mLoginTask=new LoginTask(context);
mLoginTask.execute(null);
}
}
});
}
}
--
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