简体   繁体   English

在Android中删除Fragment到底有什么用?

[英]What does removing a Fragment in Android really do?

What impact does removing a Fragment in Android have on the performance of an application. 在Android中删除Fragment对应用程序的性能有什么影响。 What I am referring to is something like: 我指的是这样的:

fragmentTransaction.remove(myFragment);

I've read the documentation about the Fragment Lifecycle Fragments and the description of the remove method in the Fragment Transaction Fragment Transaction remove() but haven't found whether calling the remove actually frees the memory occupied the Fragment's views. 我已经阅读了有关片段生命周期片段的文档以及片段事务中的remove方法的描述片段事务remove(),但还没有发现调用remove是否实际上释放了片段视图所占用的内存。

Also, is there a way that I can suspend Fragments into a low memory state? 另外,有什么方法可以将Fragments挂起成低内存状态? The idea is that in an application with many Fragments and assuming that only one Fragment is visible at a time, is there anything I can do to optimize memory? 这个想法是,在一个具有许多片段的应用程序中,并假设一次仅可见一个片段,我可以做些什么来优化内存吗?

Your app should be optimized for best performance from design. 您的应用应该经过优化,以实现最佳性能。 It should not change it's behavior upon system resources. 它不应更改系统资源上的行为。 If you are low on memory, the background apps are killed so that your app can run smoothly and you user can get the best of it. 如果您的内存不足,后台应用程序将被杀死,因此您的应用程序可以平稳运行,并且用户可以充分利用它。

Just use a fragment when you need it. 仅在需要时使用片段。 And remove it when it's not needed. 并在不需要时将其删除。 If you do it the right way, you're already optimizing your app. 如果您以正确的方式进行操作,那么您已经在优化应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM