Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class MyFragment {
boolean loaded;
private void maybeLoad() {
if (!loaded && getUserVisibleHint()) {
loaded = true;
loadMyData();
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
maybeLoad();
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
maybeLoad();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment