java - getActivity null in fragment when app resumes -


so if user on app , click home , go several other apps , come back, activity recreated , getactivity null when call on in fragment.

a solution found create static variable , store getactivity in oncreateview.

i feel isn't solution. there other way can go this?

i tried using non static variable , storing in oncreateview , onattach, getactivity null.

here error when use getactivity if don't save static variable. use in asynctask processdialog in fragment.

java.lang.nullpointerexception: attempt invoke virtual method 'android.content.res.resources$theme android.content.context.gettheme()' on null object reference 

thanks.

if sure onattach(activity activity) has null, suspect have multiple instance of same fragment @ same time. print fragment instance in onresume , check instances.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -