How to check if Fragment was restored from a backstack?

北慕城南 提交于 2020-01-01 05:28:09

问题


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?


回答1:


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/

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.

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.



来源:https://stackoverflow.com/questions/7659516/how-to-check-if-fragment-was-restored-from-a-backstack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!