Skip to content

Instantly share code, notes, and snippets.

@vestrel00
Last active August 14, 2017 17:54
Show Gist options
  • Save vestrel00/69a7f49dbe2ea078415e3bf5cac996ba to your computer and use it in GitHub Desktop.
Save vestrel00/69a7f49dbe2ea078415e3bf5cac996ba to your computer and use it in GitHub Desktop.
B: 2 - ui/common/BaseFragment.java
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