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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -