You should pass the context to the constructor or method you are calling.
java
private Context mContext;
public RandomData(Context context) {
mContext = context;
}
Edit:
Just for fun, you can actually get the application context in a static way. This is not recommended:
java
public static Context getContext() {
Context context = null;
try {
Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
Method method = activityThreadClass.getMethod("currentApplication");
context = (Application) method.invoke(null, (Object[]) null);
} catch (Exception ignored) {
}
return context;
}