首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

AsyncTask中应用ProgressDialog以及activity之间传递对象

2012-08-29 
AsyncTask中使用ProgressDialog以及activity之间传递对象public class MyTask extends AsyncTaskVoid, Vo

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");?

热点排行