当我像这样调用 popBackStack
时:
manager.popBackStack("mybackstack", FragmentManager.POP_BACK_STACK_INCLUSIVE);
属于“mybackstack”的 fragment 保留的内存会被释放吗?
我有一个管理 ListFragment
的 FragmentActivity
。每次我点击项目时,FragmentActivity
都会实例化一个新的 Fragment
,它显示有关所点击项目的一些信息,然后显示带有位图的 DialogFragment
(我在对话框关闭时回收)。我将 android:configChanges="orientation"
放在 list 中,并根据需要覆盖 onConfigurationChanged
。
最佳答案
是的, fragment 保留的内存将被释放。从文档中,
public static final int POP_BACK_STACK_INCLUSIVE
Flag for popBackStack(String, int) and popBackStack(int, int): If set, and the name or ID of a back stack entry has been supplied, then all matching entries will be consumed until one that doesn't match is found or the bottom of the stack is reached. Otherwise, all entries up to but not including that entry will be removed.
和,
public abstract void popBackStack (String name, int flags)
Pop the last fragment transition from the manager's fragment back stack. If there is nothing to pop, false is returned. This function is asynchronous -- it enqueues the request to pop, but the action will not be performed until the application returns to its event loop.
但是请注意,不能保证会立即释放此内存。
关于android - Fragment 保留的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7777764/