Last active
August 14, 2017 17:54
-
-
Save vestrel00/69a7f49dbe2ea078415e3bf5cac996ba to your computer and use it in GitHub Desktop.
B: 2 - ui/common/BaseFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class BaseFragment extends Fragment implements HasFragmentInjector { | |
... | |
@Nullable | |
private Unbinder viewUnbinder; | |
@SuppressWarnings("ConstantConditions") | |
@Override | |
public void onViewStateRestored(Bundle savedInstanceState) { | |
super.onViewStateRestored(savedInstanceState); | |
// No need to check if getView() is null because this lifecycle method will | |
// not get called if the view returned in onCreateView, if any, is null. | |
viewUnbinder = ButterKnife.bind(this, getView()); | |
} | |
@Override | |
public void onDestroyView() { | |
// This lifecycle method still gets called even if onCreateView returns a null view. | |
if (viewUnbinder != null) { | |
viewUnbinder.unbind(); | |
} | |
super.onDestroyView(); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment