I have BottomNavigationBar with five tabs. In that fragment, I'm loading data from the server. My issue is that Fragment each time loads data on changing tab. I don't want to load data every time.
I know it can be possible using onSaveInstanceState()
, but it is useful to save a small amount of data.
And one thing, There is all fragments in-app, so can't get any solution for my problem. Any help would be appreciated
MainActivity:
private boolean loadFragment(Fragment fragment) {
if (fragment != null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragmentContainer, fragment)
.commit();
return true;
}
return false;
}