I have such a problem. I have a class that works with Context
, but this class itself does not inherit from Activity
and therefore I just decided to transfer the Context
to the function that needs it, and here the problem is before I put the Context
into the function, I check it and it does not null
, but when I check it inside the function that accepted it, then it’s already in it for some reason becomes null
... And I cannot create SharedPreferences
without it. I don’t understand what kind of magic is this ... What am I doing wrong
That's how I pass it and it's not null
UserAccess.saveAccess(getApplicationContext(), cursor);
and here is the function that accepts it and in it is already null
public static void saveAccess(Context context, Cursor cursor){ SharedPreferences sPref = context.getSharedPreferences("Compare",Context.MODE_PRIVATE); }
And of course when I do getSharedPreferences()
then there is also null
How can this be?
getApplicationContext()
to doMyActivity.this
. Or where do you get it from? - Jarvis_J