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

Activity 重建的时候, fragment状态不对, 导致onLazyInitViewonSupportVisible没有被回调 #1173

Open
liaolintao opened this issue Aug 12, 2019 · 5 comments

Comments

@liaolintao
Copy link
Contributor

liaolintao commented Aug 12, 2019

Issues Guideline

Following information can help us to resolve the issue faster.

  • Library version master分支最新代码
  • Support-v4 version
  • Logs
2019-08-12 16:37:37.074 4914-4914/me.yokeyword.sample E/MainActivity: onPause
2019-08-12 16:37:37.078 4914-4914/me.yokeyword.sample I/Choreographer: Skipped 60 frames!  The application may be doing too much work on its main thread.
2019-08-12 16:37:37.143 4914-4914/me.yokeyword.sample E/ZhihuFirstFragment: onSupportVisible
2019-08-12 16:37:37.143 4914-4914/me.yokeyword.sample E/CycleFragment: onSupportVisible
2019-08-12 16:37:43.688 4914-4914/me.yokeyword.sample E/FirstHomeFragment: onDestroyView
2019-08-12 16:37:43.691 4914-4914/me.yokeyword.sample E/FirstDetailFragment: onDestroyView
2019-08-12 16:37:43.692 4914-4914/me.yokeyword.sample E/CycleFragment: onDestroyView
2019-08-12 16:37:43.694 4914-4914/me.yokeyword.sample E/ZhihuFirstFragment: onDestroyView
2019-08-12 16:37:43.695 4914-4914/me.yokeyword.sample E/ViewPagerFragment: onDestroyView
2019-08-12 16:37:43.697 4914-4914/me.yokeyword.sample E/ZhihuSecondFragment: onDestroyView
2019-08-12 16:37:43.697 4914-4914/me.yokeyword.sample E/ZhihuThirdFragment: onDestroyView
2019-08-12 16:37:43.698 4914-4914/me.yokeyword.sample E/ZhihuFourthFragment: onDestroyView
2019-08-12 16:37:43.698 4914-4914/me.yokeyword.sample E/MainActivity: onDestroy
2019-08-12 16:37:43.726 4914-4914/me.yokeyword.sample E/FirstHomeFragment: onCreate
2019-08-12 16:37:43.729 4914-4914/me.yokeyword.sample E/FirstDetailFragment: onCreate
2019-08-12 16:37:43.733 4914-4914/me.yokeyword.sample E/CycleFragment: onCreate
2019-08-12 16:37:43.737 4914-4914/me.yokeyword.sample E/ZhihuFirstFragment: onCreate
2019-08-12 16:37:43.741 4914-4914/me.yokeyword.sample E/ViewPagerFragment: onCreate
2019-08-12 16:37:43.745 4914-4914/me.yokeyword.sample E/ZhihuSecondFragment: onCreate
2019-08-12 16:37:43.748 4914-4914/me.yokeyword.sample E/ZhihuThirdFragment: onCreate
2019-08-12 16:37:43.751 4914-4914/me.yokeyword.sample E/ZhihuFourthFragment: onCreate
2019-08-12 16:37:43.753 4914-4914/me.yokeyword.sample E/MainActivity: onCreate
2019-08-12 16:37:43.927 4914-4914/me.yokeyword.sample E/MainActivity: onResume
2019-08-12 16:37:43.928 4914-4914/me.yokeyword.sample E/ZhihuFirstFragment: onResume
2019-08-12 16:37:43.928 4914-4914/me.yokeyword.sample E/FirstHomeFragment: onResume
2019-08-12 16:37:43.928 4914-4914/me.yokeyword.sample E/FirstDetailFragment: onResume
2019-08-12 16:37:43.929 4914-4914/me.yokeyword.sample E/CycleFragment: onResume
2019-08-12 16:37:43.929 4914-4914/me.yokeyword.sample E/ZhihuSecondFragment: onResume
2019-08-12 16:37:43.929 4914-4914/me.yokeyword.sample E/ViewPagerFragment: onResume
2019-08-12 16:37:43.929 4914-4914/me.yokeyword.sample E/ZhihuThirdFragment: onResume
2019-08-12 16:37:43.929 4914-4914/me.yokeyword.sample E/ZhihuFourthFragment: onResume
2019-08-12 16:37:43.988 4914-4931/me.yokeyword.sample I/Adreno: QUALCOMM build                   : 8397a22, Iaa6c380d7d
    Build Date                       : 12/17/18
    OpenGL ES Shader Compiler Version: EV031.25.03.02
    Local Branch                     : 
    Remote Branch                    : 
    Remote Branch                    : 
    Reconstruct Branch               : 
2019-08-12 16:37:43.988 4914-4931/me.yokeyword.sample I/Adreno: Build Config                     : S L 6.0.7 AArch64
2019-08-12 16:37:43.993 4914-4931/me.yokeyword.sample I/Adreno: PFP: 0x005ff110, ME: 0x005ff066
2019-08-12 16:37:43.995 4914-4931/me.yokeyword.sample I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-08-12 16:37:43.995 4914-4931/me.yokeyword.sample I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-08-12 16:37:43.996 4914-4931/me.yokeyword.sample I/OpenGLRenderer: Initialized EGL, version 1.4
2019-08-12 16:37:43.996 4914-4931/me.yokeyword.sample D/OpenGLRenderer: Swap behavior 2
2019-08-12 16:38:04.358 4914-4914/me.yokeyword.sample E/CycleFragment: onPause
2019-08-12 16:38:04.359 4914-4914/me.yokeyword.sample E/CycleFragment: onDestroyView
2019-08-12 16:38:10.634 4914-4914/me.yokeyword.sample E/CycleFragment: onCreate
2019-08-12 16:38:10.675 4914-4914/me.yokeyword.sample E/CycleFragment: onResume
2019-08-12 16:38:16.795 4914-4914/me.yokeyword.sample E/CycleFragment: onCreate
2019-08-12 16:38:16.833 4914-4914/me.yokeyword.sample E/CycleFragment: onResume
2019-08-12 16:38:54.082 4914-4914/me.yokeyword.sample E/CycleFragment: onCreate
2019-08-12 16:38:54.179 4914-4914/me.yokeyword.sample E/CycleFragment: onResume
2019-08-12 16:39:12.620 4914-4914/me.yokeyword.sample I/Choreographer: Skipped 1656 frames!  The application may be doing too much work on its main thread.
2019-08-12 16:39:12.684 4914-4931/me.yokeyword.sample I/OpenGLRenderer: Davey! duration=18475ms; Flags=0, IntendedVsync=4690586376523, Vsync=4708986376339, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=4708997706952, AnimationStart=4708998036275, PerformTraversalsStart=4708998087994, DrawStart=4709010600286, SyncQueued=4709056627005, SyncStart=4709056792890, IssueDrawCommandsStart=4709057030859, SwapBuffers=4709059638098, FrameCompleted=4709061855286, DequeueBufferDuration=477000, QueueBufferDuration=739000, 
2019-08-12 16:40:42.780 4914-4914/me.yokeyword.sample E/CycleFragment: onPause
2019-08-12 16:40:42.785 4914-4914/me.yokeyword.sample E/CycleFragment: onDestroyView
2019-08-12 16:40:45.718 4914-4914/me.yokeyword.sample I/Choreographer: Skipped 256 frames!  The application may be doing too much work on its main thread.
2019-08-12 16:40:45.742 4914-4931/me.yokeyword.sample I/OpenGLRenderer: Davey! duration=2876ms; Flags=0, IntendedVsync=4799242801960, Vsync=4802087246376, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=4802095887334, AnimationStart=4802096211292, PerformTraversalsStart=4802096315875, DrawStart=4802108075198, SyncQueued=4802116729886, SyncStart=4802116776761, IssueDrawCommandsStart=4802116988271, SwapBuffers=4802118471865, FrameCompleted=4802119817438, DequeueBufferDuration=199000, QueueBufferDuration=361000, 
2019-08-12 16:40:48.017 4914-4914/me.yokeyword.sample E/CycleFragment: onPause
2019-08-12 16:40:48.022 4914-4914/me.yokeyword.sample E/CycleFragment: onDestroyView
2019-08-12 16:40:51.639 4914-4914/me.yokeyword.sample E/CycleFragment: onPause
2019-08-12 16:40:51.643 4914-4914/me.yokeyword.sample E/CycleFragment: onDestroyView
2019-08-12 16:40:55.793 4914-4914/me.yokeyword.sample E/CycleFragment: onCreate
2019-08-12 16:40:56.071 4914-4914/me.yokeyword.sample E/CycleFragment: onResume
  • Screenshots

In addition, we do not accept issues unrelated to Fragmentation.

复现的条件:

  • activity 处于stop状态
  • activity快速resume, pause
  • activity被系统relaunch

pause之后回调了onSupportVisible, 但没回调onSupportInVisible, 问题是不是出在这里?

@liaolintao
Copy link
Contributor Author

liaolintao commented Aug 12, 2019

重建的时候没有回调safeDispatchUserVisibleHint, 也没有onHiddenChanged, 所以enqueueDispatchVisible没有执行;

2019-08-12 18:16:25.636 8116-8116/me.yokeyword.sample E/FirstHomeFragment: onDestroyView
2019-08-12 18:16:25.639 8116-8116/me.yokeyword.sample E/FirstDetailFragment: onDestroyView
2019-08-12 18:16:25.641 8116-8116/me.yokeyword.sample E/CycleFragment: onDestroyView
2019-08-12 18:16:25.642 8116-8116/me.yokeyword.sample E/ZhihuFirstFragment: onDestroyView
2019-08-12 18:16:25.645 8116-8116/me.yokeyword.sample E/ViewPagerFragment: onDestroyView
2019-08-12 18:16:25.647 8116-8116/me.yokeyword.sample E/ZhihuSecondFragment: onDestroyView
2019-08-12 18:16:25.648 8116-8116/me.yokeyword.sample E/ZhihuThirdFragment: onDestroyView
2019-08-12 18:16:25.648 8116-8116/me.yokeyword.sample E/ZhihuFourthFragment: onDestroyView
2019-08-12 18:16:25.649 8116-8116/me.yokeyword.sample E/MainActivity: onDestroy
2019-08-12 18:16:25.677 8116-8116/me.yokeyword.sample E/ZhihuFirstFragment: onAttach
2019-08-12 18:16:25.678 8116-8116/me.yokeyword.sample E/FirstHomeFragment: onAttach
2019-08-12 18:16:25.683 8116-8116/me.yokeyword.sample E/FirstHomeFragment: onCreate
2019-08-12 18:16:25.684 8116-8116/me.yokeyword.sample E/FirstDetailFragment: onAttach
2019-08-12 18:16:25.688 8116-8116/me.yokeyword.sample E/FirstDetailFragment: onCreate
2019-08-12 18:16:25.688 8116-8116/me.yokeyword.sample E/CycleFragment: onAttach
2019-08-12 18:16:25.693 8116-8116/me.yokeyword.sample E/CycleFragment: onCreate
2019-08-12 18:16:25.699 8116-8116/me.yokeyword.sample E/ZhihuFirstFragment: onCreate
2019-08-12 18:16:25.699 8116-8116/me.yokeyword.sample E/ZhihuSecondFragment: onAttach
2019-08-12 18:16:25.700 8116-8116/me.yokeyword.sample E/ViewPagerFragment: onAttach
2019-08-12 18:16:25.703 8116-8116/me.yokeyword.sample E/ViewPagerFragment: onCreate
2019-08-12 18:16:25.707 8116-8116/me.yokeyword.sample E/ZhihuSecondFragment: onCreate
2019-08-12 18:16:25.707 8116-8116/me.yokeyword.sample E/ZhihuThirdFragment: onAttach
2019-08-12 18:16:25.711 8116-8116/me.yokeyword.sample E/ZhihuThirdFragment: onCreate
2019-08-12 18:16:25.711 8116-8116/me.yokeyword.sample E/ZhihuFourthFragment: onAttach
2019-08-12 18:16:25.714 8116-8116/me.yokeyword.sample E/ZhihuFourthFragment: onCreate
2019-08-12 18:16:25.715 8116-8116/me.yokeyword.sample E/MainActivity: onCreate
2019-08-12 18:16:25.765 8116-8116/me.yokeyword.sample I/ZhihuFirstFragment: mInvisibleWhenLeave = true, mFragment.isHidden = false, getUserVisibleHint = true, mFragment.getParentFragment() == null
2019-08-12 18:16:25.765 8116-8116/me.yokeyword.sample E/ZhihuFirstFragment: onActivityCreated
2019-08-12 18:16:25.793 8116-8116/me.yokeyword.sample I/FirstHomeFragment: mInvisibleWhenLeave = true, mFragment.isHidden = true, getUserVisibleHint = true, getParentFragment isFragmentVisible = true
2019-08-12 18:16:25.794 8116-8116/me.yokeyword.sample E/FirstHomeFragment: onActivityCreated
2019-08-12 18:16:25.870 8116-8116/me.yokeyword.sample I/FirstDetailFragment: mInvisibleWhenLeave = true, mFragment.isHidden = true, getUserVisibleHint = true, getParentFragment isFragmentVisible = true
2019-08-12 18:16:25.871 8116-8116/me.yokeyword.sample E/FirstDetailFragment: onActivityCreated
2019-08-12 18:16:25.896 8116-8116/me.yokeyword.sample I/CycleFragment: mInvisibleWhenLeave = true, mFragment.isHidden = false, getUserVisibleHint = true, getParentFragment isFragmentVisible = true
2019-08-12 18:16:25.897 8116-8116/me.yokeyword.sample E/CycleFragment: onActivityCreated
2019-08-12 18:16:25.899 8116-8116/me.yokeyword.sample I/ZhihuSecondFragment: mInvisibleWhenLeave = true, mFragment.isHidden = true, getUserVisibleHint = true, mFragment.getParentFragment() == null
2019-08-12 18:16:25.899 8116-8116/me.yokeyword.sample E/ZhihuSecondFragment: onActivityCreated
2019-08-12 18:16:25.945 8116-8116/me.yokeyword.sample I/ViewPagerFragment: mInvisibleWhenLeave = true, mFragment.isHidden = false, getUserVisibleHint = true, getParentFragment isFragmentVisible = false
2019-08-12 18:16:25.945 8116-8116/me.yokeyword.sample E/ViewPagerFragment: onActivityCreated
2019-08-12 18:16:25.947 8116-8116/me.yokeyword.sample I/ZhihuThirdFragment: mInvisibleWhenLeave = true, mFragment.isHidden = true, getUserVisibleHint = true, mFragment.getParentFragment() == null
2019-08-12 18:16:25.947 8116-8116/me.yokeyword.sample E/ZhihuThirdFragment: onActivityCreated
2019-08-12 18:16:25.953 8116-8116/me.yokeyword.sample I/ZhihuFourthFragment: mInvisibleWhenLeave = true, mFragment.isHidden = true, getUserVisibleHint = true, mFragment.getParentFragment() == null
2019-08-12 18:16:25.953 8116-8116/me.yokeyword.sample E/ZhihuFourthFragment: onActivityCreated
2019-08-12 18:16:25.962 8116-8116/me.yokeyword.sample E/MainActivity: onResume
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample I/ZhihuFirstFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = true
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample E/ZhihuFirstFragment: onResume
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample I/FirstHomeFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = false
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample E/FirstHomeFragment: onResume
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample I/FirstDetailFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = false
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample E/FirstDetailFragment: onResume
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample I/CycleFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = true
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample E/CycleFragment: onResume
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample I/ZhihuSecondFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = false
2019-08-12 18:16:25.963 8116-8116/me.yokeyword.sample E/ZhihuSecondFragment: onResume
2019-08-12 18:16:25.964 8116-8116/me.yokeyword.sample I/ViewPagerFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = true
2019-08-12 18:16:25.964 8116-8116/me.yokeyword.sample E/ViewPagerFragment: onResume
2019-08-12 18:16:25.964 8116-8116/me.yokeyword.sample I/ZhihuThirdFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = false
2019-08-12 18:16:25.964 8116-8116/me.yokeyword.sample E/ZhihuThirdFragment: onResume
2019-08-12 18:16:25.964 8116-8116/me.yokeyword.sample I/ZhihuFourthFragment: onResume, mIsFirstVisible = true, mIsSupportVisible = false mInvisibleWhenLeave = true isFragmentVisible = false
2019-08-12 18:16:25.964 8116-8116/me.yokeyword.sample E/ZhihuFourthFragment: onResume

@liaolintao
Copy link
Contributor Author

我定位到是这个flagmInvisibleWhenLeave引发的问题, 我去掉这个flag, 就可以了;
看注释, 这个flag是为了解决setUserVisibleHint;

            // setUserVisibleHint() may be called before onCreate()
            mInvisibleWhenLeave = savedInstanceState.getBoolean(FRAGMENTATION_STATE_SAVE_IS_INVISIBLE_WHEN_LEAVE);

我这里没发现setUserVisibleHint这个函数有被调用

liaolintao added a commit to liaolintao/Fragmentation that referenced this issue Aug 13, 2019
…unch activity by system

YoKeyword#1173
handle quick resume/pause, avoid support visible state is wrong;
@liaolintao
Copy link
Contributor Author

我修复了;
不过, 可能还有考虑不到位的地方; pause取消了任务之后, 如果activity不是被重建, 而是直接resume, 那么fragment还是没有恢复;
因为, 我这里都是会重建, 所以这里我暂时没改;
另外, activity好像没必要强转为SupportActivity , 这可能会导致强转异常;

liaolintao added a commit to liaolintao/Fragmentation that referenced this issue Aug 14, 2019
…t resume , if mAbortInitVisible.

YoKeyword#1173
handle quick resume/pause, avoid support visible state is wrong;
@liaolintao
Copy link
Contributor Author

修复: activity快速resume, pause后, 再次resume, fragment没有回调onLazyInitView;
8af190f

@liaolintao
Copy link
Contributor Author

liaolintao commented Sep 25, 2019

修复: 在activity.onNewIntent()的时候, showHideFragment, child fragment resume后没有回调onSupportVisible

d5e79a3

liaolintao added a commit to liaolintao/Fragmentation that referenced this issue Sep 25, 2019
…led when fragment resume , if parentFragment is shown when parent fragment is not resumed.

YoKeyword#1173 (comment)
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

1 participant