Since I published a large update to one of my apps I have received hundreds of crash report, all from different motorola phones. The stack trace does not pass through my app:
EXCEPTION
java.lang.NullPointerException
at android.content.res.Configuration.updateFrom(Configuration.java:269)
at android.content.res.Resources.updateConfiguration(Resources.java:1257)
at android.app.ActivityThread.handleConfigurationChanged(ActivityThread.java:3701)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1907)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
at dalvik.system.NativeStart.main(Native Method)
It only happens once, the first time the user starts the app. I think the problem comes from this piece of code below. This code does so that the app always uses english when started, but then the user can choose to use another language that is saved at Constant.LOCALE in my SharedPreferences. The first time the program is started, the "else"-clause is executed, it might be there that the problem occurs. But really, the strangest thing is that I cant find other people that have problems with only motorola phones. Do note that it works flawlessly on all other phones.
public static void setCorrectLanguage(final Context context, final SharedPreferences preferences, final Editor editor) {
final Resources resource = context.getResources();
final Configuration cf = resource.getConfiguration();
final String choosenLanguage = preferences.getString(Constant.LOCALE, null);
final DisplayMetrics dm = resource.getDisplayMetrics();
if(choosenLanguage != null) {
cf.locale = new Locale(choosenLanguage);
resource.updateConfiguration(cf, dm);
} else {
cf.locale = new Locale("en");
resource.updateConfiguration(cf, dm);
editor.putString(Constant.LOCALE, "en");
editor.commit();
}
}