Java tutorial
//package com.java2s; import android.app.Activity; import java.util.concurrent.CountDownLatch; public class Main { private static void waitForFragmentTransaction(final Activity activity) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); activity.runOnUiThread(new Runnable() { @Override public void run() { activity.getFragmentManager().executePendingTransactions(); latch.countDown(); } }); latch.await(); } }