在 android 的非 activity 文件中获取 SharedPreferences 值?

get SharedPreferences value in a non activity file in android?

我有一个具有所有常用功能的 class,我想在那里获得一些 sharedpreferences 值。下面的代码 getSharedPreference() 给出了错误。

这是我的代码:

public class CommonFunctions {

Context mContext;
SharedPreferences sharedPreferences;

    public CommonFunctions(Context context) {
       this.mContext = context;
       sharedPreferences = getSharedPreference("MyPREFERENCES", MODE_PRIVATE);
    }

}

有什么方法可以在 java class 中获取价值吗?

使用下面的代码;

 sharedPreferences = context.getSharedPreference("MyPREFERENCES", MODE_PRIVATE);