publicclassMyTaskextendsAsyncTask<Void,Void,Void>{privatevolatileboolean running =true;privatefinalProgressDialog progressDialog;publicMyTask(Context ctx){
progressDialog = gimmeOne(ctx);
progressDialog.setCancelable(true);
progressDialog.setOnCancelListener(newOnCancelListener(){@Overridepublicvoid onCancel(DialogInterface dialog){// actually could set running = false; right here, but I'll// stick to contract.
cancel(true);}});}@Overrideprotectedvoid onPreExecute(){
progressDialog.show();}@Overrideprotectedvoid onCancelled(){
running =false;}@OverrideprotectedVoid doInBackground(Void...params){while(running){// does the hard work}returnnull;}// ...}
这两天要用一个对象的传递始终找不到好的方法,后来在传递bitMap时这个对象时有了点启发
可以讲一个类扩展为implement Serializable interface
//传递:
intent.putExtra("MyClass", obj);// to retrieve object in second Activity
getIntent().getSerializableExtra("MyClass");