在应用程序处于后台时更改语言



有人试过这个吗?

我有一个应用程序,我已经配置为根据设备的区域设置以2种不同的语言运行。

复制步骤。

(考虑到我使用法语和英语)

  1. 设置英语区域设置
  2. 加载应用程序
  3. 将应用程序发送到后台
  4. 将设备区域设置更改为法语
  5. 返回到您的应用程序并使其处于活动状态
  6. (一切看起来都很好……现在一切都用法语加载了(应该是这样))
  7. 转到另一个屏幕
  8. 接收NullPointerException

哈?!

对此有什么想法吗?

后期编辑(请求)

这是亚洲开发银行的堆叠竞赛:

06-04 00:35:27.093: WARN/dalvikvm(18434): threadid=3: thread exiting with uncaught exception (group=0x4001dc20)
06-04 00:35:27.093: ERROR/AndroidRuntime(18434): Uncaught handler: thread main exiting due to uncaught exception
06-04 00:35:27.123: ERROR/AndroidRuntime(18434): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyPackageName.__XXXXX__/com.MyPackageName.__XXXXX__.activity.MenuTabActivity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyPackageName.__XXXXX__/com.MyPackageName.__XXXXX__.activitygroup.MyProfileActivityGroup}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyPackageName.__XXXXX__/com.MyPackageName.__XXXXX__.activity.myprofile.DriverProfileActivity}: java.lang.NullPointerException
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.os.Looper.loop(Looper.java:123)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.main(ActivityThread.java:4363)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at java.lang.reflect.Method.invokeNative(Native Method)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at java.lang.reflect.Method.invoke(Method.java:521)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at dalvik.system.NativeStart.main(Native Method)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyPackageName.__XXXXX__/com.MyPackageName.__XXXXX__.activitygroup.MyProfileActivityGroup}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyPackageName.__XXXXX__/com.MyPackageName.__XXXXX__.activity.myprofile.DriverProfileActivity}: java.lang.NullPointerException
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2335)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:648)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.widget.TabHost.setCurrentTab(TabHost.java:320)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.widget.TabHost.addTab(TabHost.java:213)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at com.MyPackageName.__XXXXX__.activity.MenuTabActivity.onCreate(MenuTabActivity.java:80)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     ... 11 more
06-04 00:35:27.123: ERROR/AndroidRuntime(18434): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.MyPackageName.__XXXXX__/com.MyPackageName.__XXXXX__.activity.myprofile.DriverProfileActivity}: java.lang.NullPointerException
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2335)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at com.MyPackageName.__XXXXX__.activitygroup.MyProfileActivityGroup.startChildActivity(MyProfileActivityGroup.java:69)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at com.MyPackageName.__XXXXX__.activitygroup.MyProfileActivityGroup.onCreate(MyProfileActivityGroup.java:63)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     ... 20 more
06-04 00:35:27.123: ERROR/AndroidRuntime(18434): Caused by: java.lang.NullPointerException
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at com.MyPackageName.__XXXXX__.activity.myprofile.DriverProfileActivity.onCreate(DriverProfileActivity.java:545)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
06-04 00:35:27.123: ERROR/AndroidRuntime(18434):     ... 27 more

有人吗?

可能是您已经脱离了活动生命周期,并且在切换时没有创建一些对象,所以您应该检查下一步:

  1. 如果这在没有步骤4的情况下有效
  2. 如果某些值被缓存/没有正确翻译(比如你设置了一些字段而不是每次更新)

    mField = getString(R.string.title);
    

发现问题所在。

我有一个系统。在我进入后台时所处的屏幕中,在我的OnDestroy方法上退出(0)。

看起来,如果你把应用程序发送到后台,然后再回来,就不会调用OnDestroy了。

但是

如果您在此期间更改区域设置,然后返回到该区域设置,将调用OnDestray!!!!

这已经足够奇怪了,但更奇怪的是,在我的情况下,onDestroy被隐式调用(System.exit(0),但屏幕仍然存在。。该应用程序没有退出(更糟糕的是…它正确加载了法语!!)这令人困惑。

不管怎样。。奇怪的事情解决了。感谢您的意见。

如果没有实际看到您的代码,就无法确定问题是什么。上面的注释为您提供了一个开始调试问题的好地方。需要注意的一件事是,无论何时使用字符串作为键。如果密钥在应用程序运行期间被翻译,它将无法找到值。

如果在运行时更改区域设置,请确保在onResume()中设置local。我有一个类似的问题,当用户手动更改微调器时,它没有保持设置的语言。当应用程序进入后台时,微调器显示的是英语值,而不是西班牙语值。我只是在活动的简历上设置了我的地区。

相关内容

  • 没有找到相关文章

最新更新