I have an activity in my app where it takes several screen captures and move to next activity on a button click. I want to show some progress or status to the user while taking screenshot(It takes 5-8 seconds). I tries using AsyncTask with runOnUithread(). But no luck. Even when I wrote the whole code in doInBackground(), I don’t know why ProgressDialog starts after taking all the screenshots. What is the better way to do this? Here is my code:
public class TakeScreenShots extends AsyncTask<Void, Void, Void> {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
this.dialog = ProgressDialog.show(MyActivity.this, "MyTitle",
"Loading .....", true);
}
@Override
protected Void doInBackground(Void... params) {
MyActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
takeScreenshots();
}
});
return null;
}
@Override
protected void onPostExecute(Void unused) {
gotoNextActivity();
this.dialog.dismiss();
}
}
I got the answer from an answer in this question. I was setting a drawable to the image view. So, I kept that line on Ui Thread and remaining in doInBackground().