For some non-activity classes, like Worker, you're already given a Context object in the public constructor.
Worker(Context context, WorkerParameters workerParams)
You can just use that, e.g., save it to a private Context variable in the class (say, mContext
), and then, for example
mContext.getSystenService(Context.ACTIVITY_SERVICE)