In my app, I am using a storage access framework for writing files on the sd card. For this, I am opening an intent of document tree and inside on activity result I am receiving document URI of the sd card path.
After returning back on the activity result I am getting this document URI and then I am performing a huge task which ends in a black screen as there is a huge load on UI thread. This black screen appears for 7 to 8 seconds.
And I did resolve the black screen issue by using an async task but still other issues arise due to the async task. Instead of a black screen activity screen appears which is OK but on returning to the activity screen the UI progress loader has a problem of skipping frames, On pre execute of an async task the UI loader is skipping frames for 2 seconds and then work fine. I want to reduce skipping frames and also inside async tasks do in background method I have shifted this huge task which is exceeding time limitation and ends in about 1 minute. The huge task with a black screen nearly took 8 seconds as on the main thread without an async task.
Code for black screen
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
intent.putExtra("android.content.extra.SHOW_FILESIZE", true);
startActivityForResult(intent, 77);
and in on activity result performing a huge task
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
sdCardUri = data.getData();
if(requestCode == 77) {
documentFile = DocumentFile.fromTreeUri(this, sdCardUri);
//.... HERE ALOT OF TASK IS BEING PERFORMED AND AS IT IS RETURNING BACK TO ACTIVITY THE MAIN THREAD ENDS IN BLACK SCREEN .....
HugeTaskPerformed(documentFile);
}
after using Async task
if (resultCode == Activity.RESULT_OK) {
sdCardUri = data.getData();
if(requestCode == 77) {
documentFile = DocumentFile.fromTreeUri(this, sdCardUri);
// instead of huge task performing async task here
new MainActivity.BackgroundHugeTask(context).execute();
}
}
How should I make async do in the background work faster and also in pre execute the loader skipping for 2 seconds and then working accordingly is a mess what changes can I do to minimize them as much as possible?
Cant give you whole code but giving you a sample of where I am stuck.