片段onResume不被调用 [英] Fragment onResume not called

查看:131
本文介绍了片段onResume不被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个(假设是1,2,3& 4)片段.一次,用户将可以看到其中的任何一个.在第二个片段中,我想在用户使用它时做点什么. 现在,当用户导航到第三个片段&点击后退按钮,我想运行一些代码.我的问题是用户按下后退按钮&时没有调用onResume.来第二个片段.

解决方案

我最近遇到了同样的问题,我知道这已经太迟了,但是以防万一有人在寻找这个问题,这是我的答案:

感谢@fasteque缩小搜索范围.

仅当调用活动onResume()onPause()时才调用片段onResume()onPause().它们与活动紧密相关.

但是,如果您仍然想听听活动中的变化(例如哪个片段位于顶部)并相应地触发事件,则可以查看 解决方案

I recently bumped into the same problem, I know that its too late, but just in case some one else is looking for this, here's my answer:

Thanks @fasteque for narrowing down my search.

The fragments onResume() or onPause() will be called only when the Activities onResume() or onPause() is called. They are tightly coupled to the Activity.

But if you still want listen to the changes in your activity like which fragment is on top, and trigger events accordingly, you might wanna have a look at FragmentManager.OnBackStackChangedListener

Hope this helps :)

这篇关于片段onResume不被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆