Is it OK to keep an instance of every fragment that is created for a FragmentPagerAdapter
inside the FragmentPagerAdapter
?
Something like this:
@Override
public Object instantiateItem(ViewGroup container, int position)
switch(position){
case 0:
fragment0 = super.instantiateItem(container, position);
return fragment0;
case 1:
fragment1 = super.instantiateItem(container, position);
return fragment1;
default:
return super.instantiateItem(container, position);
}
}
Will I run into memory issues?
The idea is to do something like MyFragmentPagerAdapter.fragment0
in order to get a reference to the fragment.