android - OncreateView in Fragment is not calling with an singleInstance -


i have 2 activities , b extending 1 base class main , base class has 1 framelayout in layout including in both of activities , b respective layouts.

i checking instance creation of fragment in fragment inflating when go particular acitivity.

here code :

public class baseacitvity extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_base_acitvity);     }  } 

here firstactivity::

public class firstactivity extends baseacitvity {      public firstfragment firstfragment ;     @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.firstactivitylayout);         firstfragment = new firstfragment();         fragmentmanager fragmentmanager = getfragmentmanager();         fragmentmanager.begintransaction().replace(r.id.card_view_layout,firstfragment).commit();          button buttonclick = (button)findviewbyid(r.id.clickfirstactivity);         buttonclick.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent intent =  new intent(getapplicationcontext(),secondactivity.class);                 startactivity(intent);             }         });     }  }  public class secondactivity extends baseacitvity {      @override     protected void oncreate(bundle savedinstancestate) {         // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.secondactivity);          firstfragment fragment  = firstfragment.getinstance();          if(fragment == null)         {             fragment = new firstfragment();         }         else {          fragmentmanager fragmentmanager = getfragmentmanager();         if(fragment !=null)         {         fragmentmanager.begintransaction().replace(r.id.card_view_layout,fragment).commit();          }         }             }  } 

and fragment ::

public class firstfragment extends fragment {      private static firstfragment currentinstance;          firstfragment () {         currentinstance = this;     }      public static synchronized firstfragment  getinstance() {         if (currentinstance == null)              currentinstance = new firstfragment();         return currentinstance;     }     @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         // todo auto-generated method stub         return inflater.inflate(r.layout.fragment_one, container, false);      }  } 

now issue if have created instance of fragment in firstactivity , checking singleinstance in fragment , @ time of secondactivity why oncreatview() of fragment doesn't call instance gives not null.

please me..so there way call oncreateview() inflate fragmentlayout.


Comments

Popular posts from this blog

How do you convert a timestamp into a datetime in python with the correct timezone? -

how to display 2 form fields on same line with bootstrap -

c# - how to use buttonedit in devexpress gridcontrol -