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

Fragment 生命周期回调异常 #65

Open
lingshaofu opened this issue Jan 9, 2024 · 2 comments
Open

Fragment 生命周期回调异常 #65

lingshaofu opened this issue Jan 9, 2024 · 2 comments

Comments

@lingshaofu
Copy link

firstFragment -》secondFragment 时,firstFragment 的 onPause/onStop 不会回调,返回到 firstFragment 时,却会调用 onStart、onResume。

@laonanrenakai
Copy link

我也发现这个问题,请问解决了吗?A B C 三个页面 其中 B 页面做的生命周期只有在创建和销毁的时候才会触发生命周期,如果 B -> C 的场景下,不会触发 B 的 onStop 和 onPause。

@laonanrenakai
Copy link

看了下源码,自己修改下就可以了。
作者的自定义 FragivityFragmentNavigator 类中,第165行,navigate 方法中添加如下代码:
if (isAdded && prevFragment != null) {
ft.hide(prevFragment)
//我添加了一个生命周期回调,页面跳转的时候可以触发 onResume onPause
ft.setMaxLifecycle(prevFragment, Lifecycle.State.STARTED)
}

即可实现页面跳转的生命周期触发

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