I have an activity - MainActivity, where I initialize member variable in onCreate(...) method. This variable is then used in onStart() and onStop() methods.
Pretty simple, huh? Now the issue is, that from my users, I started to get NullPointerException crash reports, which happens in onStop() method.
I've been extensively searching for the cause, and I understand that static variables may become null when android decides to free up memory, however I couldn't find a case with member variable, which is initialized in onCreate(). The code is following:
public class MainActivity extends ActionBarActivity implements ActionBar.TabListener, SharedPreferences.OnSharedPreferenceChangeListener {
private MySvc mySvc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mySvc = DI.i().getMySvc();
...
}
@Override
protected void onStart() {
super.onStart();
mySvc.start();
}
...
@Override
protected void onStop() {
super.onStop();
//here I get NPE
mySvc.stop();
}
}
}
To make things even more mysterious, I started to get this crash reports only from certain versions of app, however the old versions have same behavior in onStart() and onStop().
I will be grateful for any hint.
Edit:
- DI.i().getMySvc(); never returns null, its done according to singleton pattern.
- MySvc is a POJO, which is instantiated in DI class