简体   繁体   English

如何检查片段是否从后台恢复?

[英]How to check if Fragment was restored from a backstack?

Is that possible to check if Fragment was restored from a backstack? 是否可以检查Fragment是否从后台恢复? For example, if I had one, then replaced by another and back to previous by tapping "back" android button? 例如,如果我有一个,然后由另一个替换,然后通过点击“返回”android按钮返回到上一个?

You need to have your own backstack and keep track of it. 您需要拥有自己的后台并跟踪它。

Look at this: http://adblogcat.com/fragment-transition-animations-while-hiding-the-previous-fragment/ 看看这个: http//adblogcat.com/fragment-transition-animations-while-hiding-the-previous-fragment/

The code holds its own stack of fragments and hides them instead of removing them, giving it the same effect as replace (with backstack) except it doesn't recreate the fragment every time so the state of the fragment is always intact. 代码拥有自己的片段堆栈并隐藏它们而不是删除它们,使其具有与replace(使用backstack)相同的效果,除非它不会每次都重新创建片段,因此片段的状态始终是完整的。

However, this code has a memory leak and I have to update it with the latest where the fragments don't persist. 但是,此代码有内存泄漏,我必须使用最新的片段不会持久化更新它。 Hope this helps. 希望这可以帮助。

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

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