我有一个异步任务正在运行,我将从连接的设备中获得结果。异步任务应在收到结果后终止并执行 onPostExcute。有没有办法执行这样一个等待回复的流程?谢谢
private void getData(){
final Context con = this.getActivity();
String tmp;
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
private ProgressDialog pd;
@Override
protected void onPreExecute() {
pd = new ProgressDialog(con);
pd.setTitle("Scanning...");
pd.setMessage("Please wait.");
pd.setCancelable(false);
pd.setIndeterminate(true);
pd.show();
}
@Override
protected Void doInBackground(Void... arg0) {
try {
tmp = Control.getReply();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
pd.dismiss();
startTestModeControl(tmp);
}
};
task.execute((Void[])null);
}