I have App on Google play, on most devices it work just fine but seems like it on some Samsung(SM-G531H,SM-G530BT), HUAWEI, Lenovo devices it crashes when getSharedPreferences
calls.
I take a reference to context from onAttach(Context context)
in fragment method (i am not calling getSharedPreferences
before onAttach
)
@Override
public void onAttach(Context context) {
super.onAttach(context);
mContext = context;
//init firebase analytics
mFirebaseAnalytics = FirebaseAnalytics.getInstance(context);
}
I have sharedPreference
helper class with constructor
public UserStats(Context mContext) {
CRASH HERE
sharedPreferences = mContext.getSharedPreferences(PREF_USER,Context.MODE_PRIVATE);
}
This is the method in fragment that invoke sharedPreference
private void setGoal(int calories){
new UserStats(mContext).setNewGoal(calories);
tvGoal.setText("Goal\n" + calories + " Cal");
}
Any idea why it happen? and how to avoid it? (i cannot debug it i receive crashes in Firebase console)