onCreate invoke multiple times in fragment in android -
i have listview in activity.on clicking on list item invokes activity.in activity have implemented viewpager , fragments.
when loads first time onresume() ,oncreate() , oncreateview() method called twice, if clicks on first list item. (i.e. loads first , second fragment view) when click on other list fragment except first calls onresume() ,oncreate() , oncreateview() methods 3 times (i.e. loads previous , after , click view )
it absoutely fine have google analytics code have track current page can put code load current page
my question googleanalytics code tracs 3 or 2 pages @ first time user doesnot gone through pages how avoid ?
my code below fragment public class mainlistactivity extends activity{ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.v(tag, "oncreate()"); customfragmentpageradapter adapter = new customfragmentpageradapter(); viewpager.setadapter(adapter); } } //code fragment adapter public class customfragmentpageradapter extends fragmentpageradapter { public customfragmentpageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int pos) { customfragment customfragment = new customfragment(); arraylist.add(customfragment); return customfragment; } @override public int getcount() { // todo auto-generated method stub return arraylist.size(); } } //code fragment public class customfragment extends fragment{ public customfragment() { super(); } @override public void onresume() { super.onresume(); log.v(tag, "oncreate -resume"); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); log.v(tag, "oncreate"); } @override public view oncreateview(layoutinflater inflater, viewgroup container,bundle savedinstancestate) { super.oncreateview(inflater, container, savedinstancestate); log.v(tag, "oncreateview"); return myanyview; } }
the problem onresume() method called fragments, including invisible ones. check gorn's answer here: how determine when fragment becomes visible in viewpager
you have override
@override public void setuservisiblehint(boolean isvisibletouser) { super.setuservisiblehint(isvisibletouser); if (isvisibletouser) { // logic }
and logic in there.
Comments
Post a Comment