wait For Activity - Android Activity

Android examples for Activity:Activity Status

Description

wait For Activity

Demo Code


import android.app.Activity;

public class Main{
    public static void waitForActivity(Activity activity) {
        waitForActivityWithTimeout(activity, 5000);
    }/* ww w .j a va2  s  .co m*/
    public static void waitForActivityWithTimeout(Activity activity,
            long timeout) {
        final long endTime = System.currentTimeMillis() + timeout;

        do {
            try {
                if (activity.isFinishing()) {
                    return;
                }
            } catch (Exception e) {
                // noop
            }
        } while (System.currentTimeMillis() < endTime);

        throw new RuntimeException("Maximum wait elapsed (" + timeout
                + ") while waiting for activity to finish");
    }
}

Related Tutorials