片段方法:连接(),分离(),删除(),更换(),popBackStack() [英] Fragment methods: attach(), detach(), remove(), replace(), popBackStack()

查看:199
本文介绍了片段方法:连接(),分离(),删除(),更换(),popBackStack()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这些功能和目的之间非常困惑。我观察到,使用替换()替换为新的现有片段。我们可以使用 addToBackStack(空)将在后面的堆栈段,所以我们可以回去pviously显示片段$ P $。现在,当一个片段添加(或更换) - onAttach() - > 的onCreate()等等....该片段的方法被称为秩序。

现在,当我们称之为删除()从我们的活动,该片段的功能被称为片段及顺序?

这是什么连接()分离()吗?的确分离()删除片段?而当这两个连接()分离()时,该片段的功能调用,并在其中为了??

此外,什么对 popBackStack发生()?我的意思是它的功能,当我们使用 popBackStack()片段从我们的活动?

被称为

和什么时候的onDestroy()被称为??

感谢你。

解决方案
  

现在,当我们调用remove()从我们的活动,该片段的功能被称为片段及顺序?

看<一href="http://developer.android.com/reference/android/app/Fragment.html">http://developer.android.com/reference/android/app/Fragment.html

的顺序是:的onPause()的onStop() onDestroyView() 的onDestroy() onDetach()

  

什么是连接()和分离()呢?是否分离()删除片段?而当这两个附加()和分离()时,该片段的功能调用,以什么顺序?

连接()分离()分别为联营或分离的片段与/从 Activty 。当安装片段 onAttach()的生命周期方法被调用,分离时的 onDetach()的生命周期方法被调用,在片段。欲了解更多信息,看看上面的链接。

  

此外,什么对popBackStack发生()?我的意思是它的功能,当我们使用popBackStack()的片段从我们的活动?

被称为

如果在片段并没有被破坏,然后在 popBackStack() ONSTART() onResume()方法被调用。如果片段已被摧毁previously,那么生命周期方法将被调用从 onAttach起()。这是一样的,当你PSS后退按钮$ P $关于活动

I am very confused between these functions and their purposes. What I have observed that using replace() replaces the existing fragment with a new one. We can use addToBackStack(null) to put that fragment in back stack so we can go back to the previously shown fragment. Now when a fragment is added (or replaced) - onAttach() -> onCreate() etc.... methods of the fragment are called in order.

Now when we call remove() on the fragment from our activity, which functions of the fragment are called and in which order?

What does attach() and detach() do? Does detach() remove the fragment? And when these two attach() and detach() are used, which functions of the fragment are called and in which order??

Also, what happens on popBackStack()?? I mean which functions are called when we use popBackStack()on the fragment from our activity??

And when does onDestroy() called??

Thank you.

解决方案

Now when we call remove() on the fragment from our activity, which functions of the fragment are called and in which order?

Look at http://developer.android.com/reference/android/app/Fragment.html .

The order is: onPause(), onStop(), onDestroyView(), onDestroy(), onDetach()

What does attach() and detach() do? Does detach() remove the fragment? And when these two attach() and detach() are used, which functions of the fragment are called and in which order??

attach() and detach() is respectively associates or detaches the Fragment with/from the Activty. When attaching the Fragment, the onAttach() lifecycle method is called, when detaching, the onDetach() lifecycle method is called in the Fragment. For more information look at the link above.

Also, what happens on popBackStack()?? I mean which functions are called when we use popBackStack()on the fragment from our activity??

If the Fragment haven't been destroyed, then on popBackStack() the onStart() and onResume() methods are called. If the Fragment has been destroyed previously, then the lifecycle methods will be called starting from onAttach(). It's the same as, when you press the back button on Activities.

这篇关于片段方法:连接(),分离(),删除(),更换(),popBackStack()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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