ncapdevi / FragNav

An Android library for managing multiple stacks of fragments
1.5k stars 220 forks source link

cachedView is unnecessary in sample #128

Closed RezaKardoost closed 6 years ago

RezaKardoost commented 6 years ago

I think caching View in BaseFragment class is unnecessary and we must inflate it again whenever onCreateView is called. I Removed if statement in this code:

if (cachedView == null) {
            cachedView = inflater.inflate(R.layout.fragment_main, container, false);
            btn = cachedView.findViewById(R.id.button);
 }

according to : https://inthecheesefactory.com/blog/fragment-state-saving-best-practices/en

And this is also the reason why those View without android:id defined isn't able to restore its View's state.

then for save and restore state of CheckBox , I added an Id for it. every thing is ok without caching.

ncapdevi commented 6 years ago

You are correct. https://github.com/ncapdevi/FragNav/commit/6b750fd381af1c52f4863ca615879421c0713170/

Thanks!