While executing the following code in an Android App, the setText happens after mainActivity.notify() is called from another Service. So, it appears as if the mainActivity.wait() is getting executed before the setText, resulting in the setText getting waited.

What may be the reason for this and how to make the Toast execute before mainActivity.wait(), so that the setText is displayed while the MainActivity waits.

```
public static Activity mainActivity;
....
startButton.setText("Processing...");
synchronized(MainActivity.mainActivity) {
                try {
                    mainActivity.wait();
                } catch (InterruptedException e) {
                }
            }
startButton.setText("Start");

```