什么时候调用onResume()而不先调用onStart()(片段生命周期) [英] When will onResume() be called without onStart() being called first (Fragment Lifecycle)

查看:68
本文介绍了什么时候调用onResume()而不先调用onStart()(片段生命周期)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

onStart()是该片段可见的时间, onResume()是该片段变为交互式的时间.因此,何时 onResume()-> onPause()-> onResume()循环何时执行而无需执行包含在内的 onStart()-> onStop()循环?

onStart() is when the Fragment becomes visible, onResume() is when the Fragment becomes interactive. So when will the onResume() -> onPause() -> onResume() cycle execute without executing the encompassing onStart() -> onStop() cycle?

就片段过渡而言,替换将破坏起始片段,调用其片段onPause()-> onStop()以及其他破坏相关生命周期的片段方法.如果过渡已替换,但将起始 fragment 添加到 ** backStack ** ,它将仍然调用 onPause()-> onStop(),但不完全破坏片段并将其与活动分离.在仅覆盖另一个片段的情况下,起始片段的 lifecycle 事件均不会执行,因为它仍然不可见(另一个片段被绘制在其上).

In terms of fragment transitions, a replace will destroy the starting fragment, calling its onPause() -> onStop() as well as other destroy related life-cycle methods. If the transition is replace but add the starting fragment to **backStack**, it will still call onPause() -> onStop() except without completely destroying the fragment and detaching it from activity. In the case of just overlaying another fragment, none of the starting fragment's lifecycle events are executed because its still there just not visible (another fragment getting drawn over it).

我不确定何时会在没有 onStart()的情况下以及 onPause() onResume()一起调用的情况下何时调用 onResume()code> onStop().

I'm not sure when onResume() will ever be called without onStart(), as well as onPause() with onStop().

连同此处已经存在的答案,使用android分割屏幕也将暂停片段而不停止它.

Along with the answers already here, using android split screen would also pause the fragment without stopping it.

推荐答案

在显示对话框时您的活动保持可见状态,或者具有透明性的其他活动显示在顶部.

When your activity stays visible while showing a dialog or another activity is shown on top that has transparency.

基本上,您的活动在 onStart() onStop()之间可见,并且您的活动在 onResume()之间是交互的onPause().当它在保持可见状态时变得不交互时,您将获得onPause而没有onStop.

Basically your activity is visible between onStart()and onStop() and your activity is interactive between onResume() and onPause(). When it it becomes uninteractive while staying visible you will get onPause without onStop.

这篇关于什么时候调用onResume()而不先调用onStart()(片段生命周期)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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