1

What is the difference between these two:

SharedPreferences prefs = getDefaultSharedPreferences(Application context);

and

SharedPreferences prefs = getDefaultSharedPreferences(Activity context);

I am confused which one to use ?i want to make prefs static so that i can use it everywhere in my app.is it ok?

mobimedia
  • 25
  • 5

1 Answers1

4

In this case it shouldn't matter.

If you look at the source code then you'll see that the context you pass in is used to create a name for your preferences. This is done by calling context.getPackageName(). So as long as both contexts return the same package name (and it should be the same for any context within your app) there is no difference between using those two.

Marcin Koziński
  • 10,835
  • 3
  • 47
  • 61