I have some shared preferences (user_id, email) that I want to access
from services and classes that are not subclassed from Activity.  I
have been trying to implement this today and keep hitting roadblocks.

In particular, when I try to access getSharedPreferences, I get a null
pointer exception. My code snippet is posted below.

My goal here is to allow read access the shared preferences to objects
and (potentially) services that aren't going to be directly exposed to
the user.  Any suggestions/examples that can help me along?


Many thanks,

Brooke

<snip>
public class MyPrefs extends Service {
    public static final String PREFS_NAME = "MyPrefs";
    private int user_id;
    private String user_email;
    private String user_password;
    private Editor editor = null;

    private SharedPreferences settings = null;


    public MyPrefs () {

        settings = this.getSharedPreferences(PREFS_NAME,
Context.MODE_PRIVATE);
    }

</snip>

the this.getSharedPreferences line causes a null pointer exception.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to