在具有某些OS版本的某些设备上,以下堆栈跟踪导致应用程序崩溃。我尝试了其他建议,但没有一个起作用。我不知道到底发生了崩溃。
ViewGroup.java AddViewInner issue
force row level security
对于所有屏幕,总是像下面这样夸大布局:
compileSdkVersion 28
minSdkVersion 17
targetSdkVersion 28
提交片段:
if (mainView == null) {
mainView = inflater.inflate(R.layout.fragment_main, container, false);
}
崩溃1:
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.setCustomAnimations(R.anim.fragment_slide_in_left, R.anim.fragment_slide_out_left, R.anim.fragment_slide_in_right, R.anim.fragment_slide_out_right);
ft.replace(R.id.main_content, fragment, fragment.getTagText());
ft.addToBackStack(fragment.getTagText());
ft.commit();
崩溃2:
java.lang.IllegalStateException:
at android.view.ViewGroup.addViewInner (ViewGroup.java:5008)
at android.view.ViewGroup.addView (ViewGroup.java:4833)
at android.view.ViewGroup.addView (ViewGroup.java:4773)
at android.view.ViewGroup.addView (ViewGroup.java:4746)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1466)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState (FragmentManagerImpl.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManagerImpl.java:1852)
at android.support.v4.app.BackStackRecord.executePopOps (BackStackRecord.java:860)
at android.support.v4.app.FragmentManagerImpl.executeOps (FragmentManagerImpl.java:2622)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether (FragmentManagerImpl.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute (FragmentManagerImpl.java:2366)
at android.support.v4.app.FragmentManagerImpl.execPendingActions (FragmentManagerImpl.java:2273)
at android.support.v4.app.FragmentManagerImpl$1.run (FragmentManagerImpl.java:733)
at android.os.Handler.handleCallback (Handler.java:790)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:171)
at android.app.ActivityThread.main (ActivityThread.java:6656)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873)
如何解决此崩溃?
答案 0 :(得分:0)
删除onCreateView
中的空检查和膨胀视图。
当您返回旧视图(mainView != null)
时,片段会尝试将其再次添加到视图层次结构中。抛出异常,因为旧视图已经有一个父视图,无法再次添加。
ViewGroup.addViewInner的来源:
if (child.getParent() != null) {
throw new IllegalStateException("The specified child already has a parent. " +
"You must call removeView() on the child's parent first.");
}