AsyncTask中使用ProgressDialog以及activity之间传递对象
public class MyTask extends AsyncTask<Void, Void, Void> {??? ? private volatile boolean running = true;?? ? private final ProgressDialog progressDialog;??? ? public MyTask(Context ctx) {?? ? ? ? progressDialog = gimmeOne(ctx);??? ? ? ? progressDialog.setCancelable(true);?? ? ? ? progressDialog.setOnCancelListener(new OnCancelListener() {?? ? ? ? ? ? @Override?? ? ? ? ? ? public void onCancel(DialogInterface dialog) {?? ? ? ? ? ? ? ? // actually could set running = false; right here, but I'll?? ? ? ? ? ? ? ? // stick to contract.?? ? ? ? ? ? ? ? cancel(true);?? ? ? ? ? ? }?? ? ? ? });??? ? }??? ? @Override?? ? protected void onPreExecute() {?? ? ? ? progressDialog.show();?? ? }??? ? @Override?? ? protected void onCancelled() {?? ? ? ? running = false;?? ? }??? ? @Override?? ? protected Void doInBackground(Void... params) {??? ? ? ? while (running) {?? ? ? ? ? ? // does the hard work?? ? ? ? }?? ? ? ? return null;?? ? }??? ? // ...??}?这两天要用一个对象的传递始终找不到好的方法,后来在传递bitMap时这个对象时有了点启发可以讲一个类扩展为implement Serializable interface //传递:?? ?intent.putExtra("MyClass", obj); ???// to retrieve object in second Activity?getIntent().getSerializableExtra("MyClass");?