Issue
I am running an AsyncTask to process multiple images. I am only able to detect that the operation should stop/cancel during run time and have to terminate the thread and return to the previous intent. How can I stop the thread running and return to the previous activity. Code so far exits current loop but continues to run and gives errors and undesired results
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}}
Solution
i recompiled and ran with logs instead of debugger and ran ok with existing code. note sure if local glitch. thanks Pavan, "return null" killed the thread totally even with debugger on, but didn't go to onpostexecute for me that time.
Answered By - ASH
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.