I'm developing an android application which has an activity. That Activity has a ViewPager which loads two fragments using a FragmentStatePagerAdapter.
This adapter is being recreated on Activity's onResume method.
This is how the bug appears:
With the activity created, I put my app in background(using device's home button)and I open other applications (specially those that consume a lot of memory). After that, I open again my application from background. I have a method like this in one of the fragments that are in viewPager:
public void doSomething(){
if(getActivity() != null) {
((HomeActivity) getActivity()).doThings():
}
}
While debugging I found that getActivity() method returns null at this point. so "doThings()" method is never executed. I also noticed that Fragment's views are created.
I don't have that problem when I don't open other apps which consume memory on my app's background time.
Is that an overflow memory error? Why getActivity() method returns null if the Fragment appears to be correctly loaded?
Thank you in advance