@Nullable
    public static Activity toActivity(final Context ctx) {
        Context iCtx = ctx;
        while (iCtx instanceof ContextWrapper) {
            if (iCtx instanceof Activity) {
                return (Activity) iCtx;
            }
            iCtx = ((ContextWrapper) iCtx).getBaseContext();
        }
        return null;
    }
If given context is or wraps an Activity, this activity is returned,
Otherwise null is returned
main/src/main/java/cgeo/geocaching/ui/ViewUtils.java