uCrop hangs due to the presence of an AsyncTask background thread in wait/sleep state or in loop
SharkFourSix opened this issue · 2 comments
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.
Not closing until confirmed.
android10
#1202 android.content.ActivityNotFoundException
Unable to find explicit activity class {com.tencent.qcloud.tim.tuikit/com.yalantis.ucrop.UCropActivity}; have you declared this activity in your AndroidManifest.xml?
com.yalantis.ucrop.UCrop.start(UCrop.java:138)
The lower version can