我遇到了一个异常,对此我一无所知。这是堆栈跟踪:
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=10; index=-1
at java.util.ArrayList.remove(ArrayList.java:480)
at android.arch.lifecycle.LifecycleRegistry.popParentState(LifecycleRegistry.java:194)
at android.arch.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:293)
at android.arch.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:332)
at android.arch.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:137)
at android.arch.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:123)
at android.arch.lifecycle.ReportFragment.dispatch(ReportFragment.java:121)
at android.arch.lifecycle.ReportFragment.onStart(ReportFragment.java:81)
at android.app.Fragment.performStart(Fragment.java:2378)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1027)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1153)
at android.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:2048)
at android.app.FragmentController.dispatchStart(FragmentController.java:188)
at android.app.Activity.performStart(Activity.java:6978)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2937)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
我正在使用android.arch.lifecycle:extensions:1.1.1
。
我获得了更多信息。
当我通过调用Fragment
从Fragment.startActivityForResult()
内部为结果启动活动时,就会发生这种情况。 Fragment
位于“奇怪”的位置。这是其持股Activity
- HoldingActivity
-- HoldingFragment
--- FragmentPagerAdapter
---- MyFragment // This is where I call the startActivityForResult
另一点可能有用的是,HoldingActivity
的每个级别都在使用ViewDataBinding.setLifecycleOwner(this)
,并且它们都附加有ViewModel
。
开始的Avtivity
托管着一个Fragment
,他们俩都使用ViewDataBinding.setLifecycleOwner(this)
并拥有一个ViewModel
。
让我知道是否还有其他方法可以帮助解决此问题,