Android Fragment Tabs being created twice on orientation change -


i'm java vet, new @ android.

anyway, following block of code activity.oncreate() method:

allcontactspage = new allcontactspage(); allgroupspage = new allgroupspage();  viewpager viewpager = (viewpager) findviewbyid(r.id.contactstabsviewpager); contactstabspageradapter tabsadapter = new contactstabspageradapter(getsupportfragmentmanager(), allcontactspage, allgroupspage); viewpager.setadapter(tabsadapter); tablayout tablayout = (tablayout) findviewbyid(r.id.contactsactivitytabs); tablayout.setupwithviewpager(viewpager);  contactsservice.loadallcontacts(this); 

the allcontactspage , allgroupspage fragments. add them tablayout using viewpager , fragmentpageadapter (contactstabspageradapter).

after this, call loadallcontacts(this) on service. "this" passed callback, when it's done calls activity, updates both fragments data should display (both fragments instance variables).

my problem that, on rotation, 2 of each fragment created. 1 version displayed in ui, version called callback. 1 displays in ui blank, , never gets data.

i've seen bunch of posts issue, haven't seen how handle fragments managed viewpager/fragmentpageradapter. want know how ensure have correct fragment reference pass data upon rotation.

once resolved, i'm going dive avoiding loading data on rotation, i've figured out how that. need figure out how make display properly.

thanks.

<activity      android:name=".youractivity"      android:configchanges="orientation|screensize|keyboardhidden" /> 

or

<activity      android:name=".youractivity"      android:screenorientation="portrait" /> 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo