android - First fragment to be added to the main activity when application starts up -


suppose creating android application has navigation drawer , set of fragments. when user clicks on option in navigation drawer corresponding fragment loaded. application has 1 activity (main activity) , has no view.

when application first started fragment gets loaded main activity? how application know fragment loaded first without user interaction? how set custom fragment loaded automatically when application starts?

thank you

you perform same fragmenttransaction use replace fragment on user interaction , in oncreate() method of activity. have check if savedinstancestate null this:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      if(savedinstancestate == null) {         fragmentmanager manager = getfragmentmanager();         fragmenttransaction transaction = manager.begintransaction();         transaction.replace(r.id.flfragmentcontainer, mainfragment.newinstance());         transaction.commit();     } } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -