public static void showToastWhenPossible(Context context, String message) {
        Activity activity = Restarter.getForegroundActivity(context);
        if (activity != null) {
            Restarter.showToast(activity, message);
        } else {
            // Only try for about 10 seconds
            showToastWhenPossible(context, message, 10);
        }
    }
Show a toast when an activity becomes available (if possible).
freeline-runtime/src/main/java/com/antfortune/freeline/util/Restarter.java