android - Fragmentation, onRestart(), and Null Pointers -- What am I doing wrong? -


i have 3 fragments contained within main activity via viewpager. i'm trying allow myself call methods on objects of fragment classes different lifecycle callbacks in main activity, namely onrestart(), can refresh content via backend call. more specific, 1 of fragments contains "live feed" of images people posting, , user gets posting activity via 1 of fragments.

right now, problem i'm trying solve when user goes posting activity , puts picture, live feed in fragment come isn't getting refreshed. this, need call backend , ui update methods in fragment main activity's onrestart().

but i'm running these null pointer exceptions -- here's code looks in fragment:

  public void refreshui(){      activity = getactivity();     appcontext = thisapp.appcontext();     view = getview();      peopleheader = (textview) view.findviewbyid(r.id.people_header);     peoplelinearlayout = (linearlayout) view.findviewbyid(r.id.local_people_linearlayout);      ..... (various other instantiations)... } 

the npes coming either getactivity() or of ui instantiations. call code onactivitycreated() , works expected. however, if try call code again on fragment object onrestart(), crash.

what's happening? can't figure out why go bad on me.

thanks much.

when activity destroyed , recreated, fragments destroyed , recreated it. can have @ fragment/activity lifecycle explanation here.

what means reference keep disappears, fragment there object. need reference new object.

you can check this answer on how that. explains getting references fragments created viewpager adapter.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -