wait For Activity With Timeout - Android Activity

Android examples for Activity:Activity Status

Description

wait For Activity With Timeout

Demo Code


//package com.java2s;
import android.app.Activity;

public class Main {
    public static void waitForActivityWithTimeout(Activity activity,
            long timeout) {
        final long endTime = System.currentTimeMillis() + timeout;

        do {//  www  .  j av  a2  s . c  o m
            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