I want to access SharedPreference within my background service i'd used PreferenceManager.getDefaultSharedPreferences()
but it gives nullpoint Exception
Thanks
These preferences will automatically save to SharedPreferences as the user interacts with them. To retrieve an instance of SharedPreferences that the preference hierarchy in this activity will use, call getDefaultSharedPreferences(android. content. Context) with a context in the same package as this activity.
Open the device monitor by clicking it. Then you need to select the File Explorer tab in the device monitor. Find the data folder and find another data folder inside it. It will contain a folder having the name of your application package and there will be the desired SharedPreferences.
SharedPreferences are stored in an xml file in the app data folder, i.e. SharedPreferences added during runtime are not stored in the Eclipse project. The default shared preferences file would actually be: /data/data/<package>/shared_prefs/<package>_preferences. xml .
Shared Preferences is the way in which one can store and retrieve small amounts of primitive data as key/value pairs to a file on the device storage such as String, int, float, Boolean that make up your preferences in an XML file inside the app on the device storage.
You have to use the Context like this:
Context ctx = getApplicationContext();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With