Skip to content

uCrop hangs due to the presence of an AsyncTask background thread in wait/sleep state or in loop #550

@SharkFourSix

Description

@SharkFourSix

Do you want to request a feature or report a bug?
Report a bug

What is the current behavior?
UCrop activity becomes disabled when an AsyncTask instance is run in the background and if the doInBackground method is in a loop or the task's thread is in a wait state.

What is the expected behavior?

UCrop activity should not stall/hang.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

It seems UCrop doesn't play well with AsyncTasks running in a foreground service?

Here's a simple class to reproduce this. Fist, launch the task and then launch UCrop. It could be Android's scheduling system. IDK.

public class AnActivity extends AppCompatActivity {
    @Override protected void onCreate(...){
        // setup some views. Possibly a button to invoke uCrop
        startService(new Intent(this, AService.class));
    }
}
public class AService extends Service {
    public void onCreate(){
        new BlockingTask().execute();
    }
  // ...
}
public static class BlockingTask extends AsyncTask<Void, Void, Void> {
        @Override
        protected Void doInBackground(Void... voids) {
            Log.v("BlockingTask", "doInBackground");
            try {
                // Will block UCrop for 60 seconds.
                // Even wrapping #execute in another thread will still block UCrop
                Thread.sleep(TimeUnit.SECONDS.toMillis(60));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Log.v("BlockingTask", "doInBackground");
            return null;
        }
    }

Please attach any image files, URL and stack trace that can be used to reproduce the bug.

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop?

uCrop 2.2.3-native
SDK 28, Android Pie

EDIT

My solution was to move my worker method to a Thread class instead of using AsyncTask.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions