android - First fragment to be added to the main activity when application starts up -
suppose creating android
application has navigation drawer
, set of fragment
s. 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
Post a Comment