Skip to content Skip to sidebar Skip to footer

Access Shared Preference From A Service

I am fairly new to android. I have an activity in my application. I used shared preferences to store some data related to that activity. Now, how can I access those stored data fr

Solution 1:

Seeing as you're already in an application component that extends Context, you can simply use:

SharedPreferencesprefs=this.getSharedPreferences("Pref name", Context.MODE_PRIVATE);

Make sure you call this in or after onCreate().

Solution 2:

Have a look here http://developer.android.com/guide/topics/data/data-storage.html#pref

You can only access SharedPreferences within the same application ID.

If you want to access it from another application's context, you could put the mode to world-readable (but stronly not recommended and depreciated in API 17).

Post a Comment for "Access Shared Preference From A Service"