Save the state of navigation drawer fragments

微笑、不失礼 提交于 2019-12-05 18:57:52

To not loose the state of your fragments when switching from one to another you should do "new Fragment()" only once, and keep the instance in a global variable.

But this will not fix the rotation problem. For the rotation problem, you should read this => http://blog.sqisland.com/2014/06/navigationdrawer-creates-fragment-twice.html Not easy but I haven't found another way yet.

define fragment object as static in the class and in newInstance method only initialise is fragment is null otherwise just return the fragment.

This will solve your problem.

but for orientation change you will have to use on saveinstancestate method.

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