我怎样才能在工作人员中获得我的共享偏好

How can I get my sharedpreferences in worker

我有一名工作人员,想访问我的共享首选项。在我的工人class我做不到

this.getSharedPreferences

getSharedPreferences

不是静态的所以我做不到

MainActivity.getSharedPreferences

有人知道怎么做吗?

你可以直接从Workerclass调用getApplicationContext()方法来获取整个应用的Context,在这个用例中应该是合理的。