Delay if function contains a cloud function inside

I have a function activated when some button is pushed. It has two actions inside of it:

  1. Show progress dialog;
  2. Run a Parse cloud function.

So it looks like this:

public void myButtonFunction()
{
progressDialog.show();
someParseCloudFunctionWithCallback();
}

The problem is that when I push the button using this function the progress dialog is not shown immediately but with some delay. If I delete the cloud function from myButtonFunction then it shows up it immediately. So it looks like the presence itself of a cloud function inside the myButtonFunction creates the delay of showing the dialog that is the first action! Does anybody know how to solve this problem? I want the the dialog is shown immediately.

PS: Before I used AsyncTask class where I put the progressDialog.show() in “onPreExecute” and the cloud function in “doInBackGround”. This solved the problem and the dialog was shown immediately when push the button. But this class is about to be depricated so I need another solution.

Thank you!