Android Fragment: getActivity() returning null when coming from background -


i'm developing android application has activity. activity has viewpager loads 2 fragments using fragmentstatepageradapter.

this adapter being recreated on activity's onresume method.

this how bug appears:

with activity created, put app in background(using device's home button)and open other applications (specially consume lot of memory). after that, open again application background. have method in 1 of fragments in viewpager:

public void dosomething(){     if(getactivity() != null) {         ((homeactivity) getactivity()).dothings():     } } 

while debugging found getactivity() method returns null @ point. "dothings()" method never executed. noticed fragment's views created.

i don't have problem when don't open other apps consume memory on app's background time.

is overflow memory error? why getactivity() method returns null if fragment appears correctly loaded?

thank in advance

you can override onattach(activity) method in fragment , reference activity there.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -