我正在运行AsyncTask来处理多个图像。我只能检测到操作应该在运行时停止/取消,并且必须终止线程并返回到先前的意图。如何停止线程运行并返回上一个活动。到目前为止,代码退出当前循环但继续运行并产生错误和不良结果
private class processImagesThread extends AsyncTask<String, Integer, Bitmap> {
@Override
protected Bitmap doInBackground(String... params) {
for (int i = 0; i < ArrayUris.size(); i++) {
if(failCondition){
Intent resultIntent = new Intent();
setResult(Activity.RESULT_CANCELED);//normally return ok and a URI
this.cancel(true);
finish();
break;
}
}
//further processing continues after failcondition
}
@Override
protected void onCancelled()
{
super.onCancelled();
Intent resultIntent = new Intent();
setResult(Activity.RESULT_CANCELED);
}
}
//previous intent
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_CANCELED) { //Toast to user}}
答案 0 :(得分:0)