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

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -