HandlerThread线程、AsyncTask的取消
? ? ? 在项目中遇到了登录取消的问题,由于登录用的是使用HandlerThrad新开一条线程的做法,网上的教程都是设置标志位或者使用HandlerThread的private ProgressDialog processDialog;processDialog.setOnCancelListener(new OnCancelListener() {@Overridepublic void onCancel(DialogInterface dialog) {iscancel = true;}}?
AsyncTask在这个问题上处理任务取消的方法和HandlerThread类似,只是线程取消是再handleMessage方法中处理,而AsyncTask对应HandlerMessage的方法是onPostExecute。AsyncTask比使用HandlerThread更加轻量,推荐使用。?
?