2

I am trying to retrieve data from sharedPreferences:

    public static void loadArray(Context mContext) {
    SharedPreferences mSharedPreference1 = PreferenceManager.getDefaultSharedPreferences(mContext);
    WorkList.clear();
    int size = mSharedPreference1.getInt("Status_size", 0);
    for (int i = 0; i < size; i++) {
        WorkList.add(mSharedPreference1.getString("Status_" + i, null));
    }
}

i got this code but don't know how to call this method. I try to call this method in the same non-activity class.

1 Answers1

1

Create an app Singleton Class by following this link

Then you can call the method by loadArray(AppSingleton.getInstance().getContext())

Once you are a bit comfortable and have understood the concept switch to using Dagger2 to handle singletons

sharp
  • 1,191
  • 14
  • 39
Joey Pinto
  • 1,735
  • 1
  • 18
  • 34