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

有机会适配下androidX的Fragment切换 #12

Open
phoenixsky opened this issue Aug 21, 2021 · 0 comments
Open

有机会适配下androidX的Fragment切换 #12

phoenixsky opened this issue Aug 21, 2021 · 0 comments

Comments

@phoenixsky
Copy link

androidX的fragment已经不需要用setUserHint方法了

On the new version of androidx.fragment (from 1.1.0+), Fragment.setUserVisibleHint will still get called if your FragmentStatePagerAdapter is using the old behavior, specified by BEHAVIOR_SET_USER_VISIBLE_HINT.

If you have constructed your FragmentStatePagerAdapter and passed BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, then Fragment.setUserVisibleHint will no longer be called inside FragmentStatePagerAdapter.instantiateItem.

NOTE: you can still call the deprecated Fragment.getUserVisibleHint if you have specified BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT in your FragmentStatePagerAdapter, but be advised that it will return true even though Fragment.isResumed() will return false.

新版本的fragment切换可以直接采用onResume来判断是否显示,但是需要在切换fragment时 加入以下代码

setMaxLifecycle(fragment, Lifecycle.State.RESUMED);

If you are manually calling this method, use FragmentTransaction.setMaxLifecycle(Fragment, Lifecycle.State) instead. If overriding this method, behavior implemented when passing in true should be moved to onResume(), and behavior implemented when passing in false should be moved to onPause().

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