Your colleague is right: it's not good practice to use snippet references in your activity variables. Your activity will be destroyed, for example. when you rotate the screen, and links can lead to memory leak.
For your problem, move the code that initializes the ViewPager (your initSectionsPagerAdapter() method) to onResume . It will be called up when the activity first starts, and also when it becomes visible, for example. when another application that was on top is closed. You do not need the current code in onResume .
EDIT:
When you create a fragment, do not store the link to it in activity variables. To access the fragments later, you can use:
FragmentManager fm = this.getFragmentManager(); GluehweinMapFragment f1 = (GluehweinMapFragment)fm.getFragments().get(0); // to get one fragment for (Fragment f : fm.getFragments()) { // to loop through fragments and checking their type if (f instanceof GluehweinMapFragment) { } }
source share