应用程序崩溃后更改手机语言并从后台重新启动
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了应用程序崩溃后更改手机语言并从后台重新启动相关的知识,希望对你有一定的参考价值。
我正在开发一个android应用程序,并面临一些奇怪的问题。当应用程序在后台和用户更改手机语言并从后台重新启动应用程序然后应用程序停止。
奇怪的是,只有当我将语言从英语改为法语时,应用程序才会崩溃,但是当从法语改为英语或其他语言时,它会在没有任何崩溃的情况下发挥作用。下面是错误日志 -
进程:com.myapp,PID:17745 java.lang.IllegalStateException:Activity已在android.support.v4.app.BackStackRecord.commitInternal的android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1515)中销毁。 (BackStackRecord.java:638)在android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:621)在android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:162)在android.support。在Android.support.v4.view.ViewPager.onMeasure(ViewPager.java)的android.support.v4.view.ViewPager.populate(ViewPager.java:1025)上的v4.view.ViewPager.populate(ViewPager.java:1177) 1545)在android.view.View.measure(View.java:18794)在android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)在机器人。 view.View.measure(View.java:18794)在android.widget.Rel上的android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715) ativeLayout.onMeasure(RelativeLayout.java:461)在android.view.View.measure(View.java:18794)在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)在android.widget.LinearLayout.measureChildBeforeLayout(的LinearLayout .java:1465)android.widget.Line中的android.widget.Linear.measureVertical(LinearLayout.java:748)android.view.View.measure(View.java:18794)的android.widget.LinearLayout.onMeasure(LinearLayout.java:630)在android.sview.View.measure(View.java:18794)的android.sview.View.measure(View.java:18794)上的android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1075)处于android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951) android.widget.FrameLayout.onMeasure(FrameLayout.java:194)在android.view.view.measure(View.java:18794)的android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135) .view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)位于android.widget.LinearLayout.measur的android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465) eVertical(LinearLayout.java:748)在android.widget.LinearLayout.onMeasure(LinearLayout.java:630)在android.view.View.measure(View.java:18794)在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java :5951)android.widget.FrameLayout.onMeasure(FrameLayout.java:194)在android.view.vision.measure(View.java:18794)android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)at android .widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)在android.widget.LinearLayout.measureVertical(LinearLayout.java:748)在android.widget.LinearLayout.onMeasure(LinearLayout.java:630)在android.view.View。测量(View.java:18794)在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)的android.widget.FrameLayout.onMeasure(FrameLayout.java:194)com.android.internal.policy.PhoneWindow $ DecorView .onMeasure(PhoneWindow.java:2643)在Android.vie上的android.view.View.vision.measure(View.java:18794)上的android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100) w.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)在android.view.ViewRootImpl $ TraversalRunnable .run(ViewRootImpl.java:6013)在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:858)的android.view.Chopographer.doCallbacks(Choreographer.java:670)android.view.Choreographer.doFrame( Choreographer.java:606)在android.view.Handler.dispatchMessage(Handler.java)的android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:844)android.os.Handler.handleCallback(Handler.java:739) :95)在android.app.Looper.loop(Looper.java:148)的android.app.ActivityThread.main(ActivityThread.java:5417)at java.lang.reflect.Method.invoke(Native Method)at com。 android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
这似乎是从嵌套片段添加的支持功能中出现的错误。
基本上,FragmentManager在与活动分离时最终会出现内部状态损坏。
在片段上试试这个:
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
如果有效,请告诉我。
问候,
这是因为当您更改设备的语言时,会创建片段的新实例,并且应用程序会尝试查找新实例。
您需要将片段的实例存储在List中以避免此类型的异常。
如果您提供添加片段的代码,那么它将更加清晰。
以上是关于应用程序崩溃后更改手机语言并从后台重新启动的主要内容,如果未能解决你的问题,请参考以下文章