[英]What happens when a fragment called from backstack?
I have a container fragment.I load fragment inside of it.When i wanna load a new fragment i use this code 我有一个容器片段。我在其中加载片段。当我想加载一个新片段时,我使用此代码
FragmentTransaction ft=activity.getSupportFragmentManager().beginTransaction();
ft.add(R.id.mainframe,new_fragment_here).hide(getCurrentFragment()).addToBackStack(null).commit();
What I'm asking is when i hide a fragment can it be removed by garbage collector when memory is less? 我要问的是,当我隐藏一个片段时,如果内存不足,垃圾收集器可以将其删除吗?
And when i want to get back to old fragment i simply use getFragmentManager().popBackStack();
当我想回到旧片段时,只需使用
getFragmentManager().popBackStack();
When i use this code does my fragment and its images or videos permanantly destroyed? 当我使用此代码时,我的片段及其图像或视频会被永久破坏吗?
Does this kind of usage cause out of memory error? 这种用法会导致内存不足错误吗?
I have to say nearly all my fragment show images from web with glide.Some fragments only show one image and others show more than that with recyclerview. 我不得不说几乎我所有的片段都显示了来自网络的图像,有些片段只显示一个图像,而其他片段则显示更多。
I believe what you are trying to ask is about the lifecycle of the Fragment and how GC work's for Fragment in the back-stack. 我相信您要问的是有关Fragment的生命周期以及GC在后端堆栈中如何工作的信息。
From my observation and knowledge when you add a Fragment to the backstack then Fragment is in the RAM of the device but if there are many number of task(Fragment) alive then GC might do a force destroy of the Fragment based on the need. 根据我的观察和知识,当您将Fragment添加到Backstack时,该Fragment位于设备的RAM中,但是如果有许多活着的task(Fragment),则GC可能会根据需要强行破坏Fragment。
For better understanding of the fragment lifecycle and what happens to the Fragment in Backstack refer this Flow chart. 为了更好地了解片段的生命周期以及Backstack中的片段发生了什么,请参考此流程图。
This diagram might be little complex but it will help you understand how fragment work's. 该图可能有点复杂,但可以帮助您了解片段的工作原理。
NOTE: when you pop/replace a fragment then the fragment itself is destroyed you can check it by keeping a breakPoint at onDestroy()
of the Fragment. 注意:弹出/替换片段时,片段本身会被破坏,您可以通过在片段的
onDestroy()
处保留一个breakPoint来对其进行检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.