According to the documentation,
Called when activity start-up is complete (after onStart() and onRestoreInstanceState(Bundle) have been called). Applications will generally not implement this method; it is intended for system classes to do final initialization after application code has run.
Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.
It is not advised to use this method. However, I use it to tweak some elements after onCreate
. I see that some people use it to do something between onResume()
and they are advised not to do this as they cannot rely on this method (due to its bad documentation).
So, can I use the tweaking here (it does not rely on onResume
at all)?
Do you ever use this method and when/why?
using onPostCreate as a callback method from subclass' onCreate will notify that all creation is finished. Example: If you have activities sharing the same layout, then you can use the onPostCreate to add onClickListeners etc. If you are overriding onPostCreate, it is best to make the call to super.
As onCreate() of an Activity is called only once, this is the point where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById to programmatically interact with widgets in the UI, calling managedQuery(android.
onPostCreate can be useful if you are making your own "super-class" extension of Activity with functionality that all your activities shall share.
using onPostCreate as a callback method from subclass' onCreate will notify that all creation is finished. Example: If you have activities sharing the same layout, then you can use the onPostCreate to add onClickListeners etc
If you are overriding onPostCreate, it is best to make the call to super.onPostCreate at the end of your implementation.
Google uses onPostCreate() in their example project for Navigation Drawer. ActionBarDrawerToggle needs to sync after orientation change lets say :)
@Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); // Sync the toggle state after onRestoreInstanceState has occurred. mDrawerToggle.syncState(); }
So I think onPostCreate() should be used only in some specific situations...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With