使用配置时摩托罗拉在 Android 上特定的崩溃

发布于 2024-09-08 23:18:21 字数 1818 浏览 2 评论 0原文

自从我对我的一个应用程序发布了重大更新以来,我收到了数百份崩溃报告,全部来自不同的摩托罗拉手机。堆栈跟踪不会通过我的应用程序:

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)

它只发生一次,即用户第一次启动应用程序时。我认为问题出在下面这段代码上。此代码使应用程序在启动时始终使用英语,但随后用户可以选择使用保存在我的 SharedPreferences 中 Constant.LOCALE 中的另一种语言。程序第一次启动时,执行“else”子句,可能就是在那里出现问题。但实际上,最奇怪的是我找不到其他人只使用摩托罗拉手机出现问题。请注意,它在所有其他手机上都能完美运行。

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();
    }
}

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();
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎的声音 2024-09-15 23:18:21

我在使用摩托罗拉 Quench 时也遇到了类似的问题。
您可以通过进入“设置”->“检测您可以使用的区域设置”来尝试检测哪些区域设置可供您使用。区域设置和时间 ->尝试单击“英语”或“英语(加拿大)”或任何您感兴趣的内容,然后查看调试日志(使用 DDMS)以查看返回的区域设置。
例如。
06-11 02:17:51.831:INFO / BlurServiceMother(129):onConfigurationChanged():区域设置已更改,登录以告诉服务器:fr_FR

这将指示您可用的区域设置。

就我而言,我提供了“en”和“fr”作为 2 个区域设置,但我们 Quench 没有任何一个可用,因此如果无法更改为其中之一,则尝试“en_CA”或“fr_FR”,如果它仍然失败,然后从方法返回(或显示适当的消息),表明不支持该语言...

希望它有帮助!

I encountered a similar problem with Motorola Quench.
You can try detecting what locale's are available to you by going into Settings -> Locale and Time -> Try clicking on English or English (Canada) or whatever you're interested in and look through the debug logs (using DDMS) to see the locale returned.
Eg.
06-11 02:17:51.831: INFO/BlurServiceMother(129): onConfigurationChanged(): locale changed, logging in to tell server: fr_FR

This will indicate the Locale available to you.

In my case, I was supplying "en" and "fr" as the 2 Locale's but we the Quench doesn't have either available so if it failed to change to one of these then try "en_CA" or "fr_FR" and if it still fails then just return from the method (or display appropriate message) indicating that the language is not supported...

Hope it helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文