像下面这样
class GetStuffAsyncly extends AsyncTask<String, String, String> { String dialogString; ProgressDialog dialog; Context context; AsyncListener listener; // my vars.... public GetStuffAsyncly(String dialogMessage, Context con, AsyncListener listener) { this.dialog = new ProgressDialog(con); this.dialogString = dialogMessage; this.context = con; this.listener = listener; } @Override protected void onPreExecute() { super.onPreExecute(); listener.onTaskStarted(); } @Override protected String doInBackground(String... args) { // do stuff in background... return data; } protected void onPostExecute(String jsonString) { // dismiss the dialog after getting all data dialog.dismiss(); listener.onTaskFinished(jsonString); }}和听众课
public interface AsyncListener { void onTaskStarted(); void onTaskFinished(String data);}你可以这样打电话
new GetStuffAsyncly(message, this, new AsyncListener() { @Override public void onTaskStarted() { //do your stuff } @Override public void onTaskFinished(String data) {//Do your stuff; } }).execute(parameter);


