code: public static Activity scanForActivity(Context context) {
          if (context == null) return null;
  
          if (context instanceof Activity) {
              return (Activity) context;
          } else if (context instanceof ContextWrapper) {
              return scanForActivity(((ContextWrapper) context).getBaseContext());
          }
  
          return null;
      }
docs: Get activity from context object
  
  @param context context
  @return object of Activity or null if it is not Activity