android - Why is it necessary to check savedInstanceState inside of OnCreate? -
this question has answer here:
what purpose of if block in oncreate()
method? why necessary check if savedinstancestate null?
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); if (savedinstancestate == null) { getsupportfragmentmanager().begintransaction() .add(r.id.container, new placeholderfragment()) .commit(); } }
when activity recreated, such after screen rotation or other configuration change, fragments automatically reattached. checking if savedinstancestate == null
, ensure not re-adding fragment has been added you.
Comments
Post a Comment