Hello.
In my Android application, I have to call the getSharedPreferences in
non-activity classes.
In order to avoid passing a Context object to each constructor of
these classes (and because many of them are classes with only static
methods which don't have a constructor), I have implemented these
steps :
The main activity of my application (which is launched at startup) is
called Dispatcher.
In the onCreate method of this class, I keep a reference to the
created Dispatcher object in a static public variable of the
Dispatcher class which can be accessed from any class in the project.
Here is the squeleton of this class:
public class Dispatcher extends Activity {
public static Dispatcher ref;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ref = this;
...
}
...
}
This class calls this method to start other activities :
startActivityForResult(new Intent(Dispatcher.this,
RegisterScreen.class), S.REG);
The problem is that when I try to use the
Dispatcher.ref.getSharedPreferences(...) method in one of my classes,
on some devices it works well and on other devices, I get a
NullPointerException.
Can you please help me to solve this problem.
Thank you.
Best regards.
Patrick.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en