Sapp
Sapp

Reputation: 1803

How do I preform an action, after a brief pause?

I have an app that crops faces - something the app can do in a nanosecond, but I want the user to think it takes a bit longer. So in a case on a button click, Here is what I have:

final ProgressDialog dialog = ProgressDialog.show(Main.this, "",
                        "Cropping faces...", true);
                dialog.show();

            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    dialog.dismiss();
                }
            }, 3000);
                            cropFaces();
                            return

}

The dialog shows fine and the faces crop fine too. The problem is - when the user runs the app, the two happen simultaneously on the screen.

Is there a way to make it so the dialog appears, 3 seconds elapse on screen, and then the cropFaces runs? That way it will look like it cropped the faces in a few seconds and then the new page appears. Thanks!

Upvotes: 0

Views: 199

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006869

Put your call to cropFaces() inside your run() method, so it is delayed as well.

Upvotes: 2

Related Questions