如何检查是否片段从backstack恢复?片段、backstack

2023-09-06 04:45:59 作者:- 装社么富二代。

这有可能,以检查是否片段是从backstack恢复?举例来说,如果我有一个,然后由另一取代,回到previous通过点击后退按钮,机器人?

Is that possible to check if Fragment was restored from a backstack? For example, if I had one, then replaced by another and back to previous by tapping "back" android button?

推荐答案

您需要有自己的backstack并跟踪它。

You need to have your own backstack and keep track of it.

看看这个:的http://adblogcat.com/fragment-transition-animations-while-hiding-the-$p$pvious-fragment/

在code拥有自己的碎片堆,并隐藏删除它们,给它的效果一样更换(与backstack)只是它不每次都重新创建片段使该片段的状态是他们,而不是始终不变。

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.

然而,这code的内存泄漏,我不得不与最新那里的碎片不会持续更新。希望这有助于。

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.