Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FragmentAnimator.getEnter()真的会空指针 #907

Closed
tyzero opened this issue Jun 19, 2018 · 1 comment
Closed

FragmentAnimator.getEnter()真的会空指针 #907

tyzero opened this issue Jun 19, 2018 · 1 comment

Comments

@tyzero
Copy link

tyzero commented Jun 19, 2018

抱歉,我又来了

https://github.com/YoKeyword/Fragmentation/issues/894
上次896的问题修复了,但还是能在Crash log 捕捉到 getEnter是空的crash.

查了下,非常诡异,并不能用 开始 single Activity 的模式 来重现。我自己也没办法重现 只能在log 找到这种crash。

这一次是在 SupportFragmentDelegate里面的 oncreate 出现的

if (savedInstanceState == null) {
      getFragmentAnimator();
} else {
     mSaveInstanceState = savedInstanceState;
     mFragmentAnimator=savedInstanceState.getParcelable(TransactionDelegate.FRAGMENTATION_STATE_SAVE_ANIMATOR);

//这里拿出来的 mFragmentAnimator  有可能是null
  

这是Log

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int me.yokeyword.fragmentation.anim.FragmentAnimator.getEnter()' on a null object reference
at me.yokeyword.fragmentation.helper.internal.AnimatorHelper.initEnterAnim(AnimatorHelper.java:63)
at me.yokeyword.fragmentation.helper.internal.AnimatorHelper.notifyChanged(AnimatorHelper.java:29)
at me.yokeyword.fragmentation.helper.internal.AnimatorHelper.(AnimatorHelper.java:24)
at me.yokeyword.fragmentation.SupportFragmentDelegate.onCreate(SupportFragmentDelegate.java:120)
at me.yokeyword.fragmentation.SupportFragment.onCreate(SupportFragment.java:48)

所以我只好
在自己的BaseFragment里 重写 SupportFragment 的onCreate,判断如果savedInstanceState没有FragmentAnimator,就给他加入一个DefaultVerticalAnimator

override fun onCreate(savedInstanceState: Bundle?) {
    if (savedInstanceState != null) {
      val fa = savedInstanceState.getParcelable<FragmentAnimator?>("fragmentation_state_save_animator")
      if (fa == null) {
              savedInstanceState.putParcelable("fragmentation_state_save_animator", DefaultVerticalAnimator())
            }
        }
   super.onCreate(savedInstanceState)

}

目前只观测到 7.0(Moto G (5)) 会有这个crash,将继续保持观察

  • Library version me.yokeyword:fragmentation:1.3.3
  • Support-v4 version com.android.support:support-v4:27.1.1
@YoKeyword
Copy link
Owner

7.0才有这个问题的话,不排除是该机型的Parcelable机制出现BUG

取的时候为null,要么onSaveInstace时为空, 要么取的时候反Parcelable时出现问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants