关于onPostCreate——Activity彻底运行起来之后的回调

今天偶然间发现了一个貌似很有用处的接口

protected void onPostCreate (Bundle savedInstanceState)
  1. Since: API Level 1

  2. 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.

  3. Derived classes must call through to the super class's implementation of this method. If they do not, an exception will be thrown.

记得之前想要在Activity布局完成,彻底跑起来之后,再获取当前Activity的窗口中,某个View的宽高,之前用的办法很土,弄个Handler,发个Message出来,使用sendMessageDelayed或者sendEmptyMessageDelayed。
说白了就是延迟若干时间之,等Activity彻底跑起来之后,再取获取View的宽高。
使用这个办法,总是有一种担心:delay的时间太长了,害怕使用这个获取的宽高的值的时候,自己获取宽高的函数还没被调用;delay的时间太短了,又害怕在某些配置比较低的机型上,在delay的时间内Activity没能彻底的跑起来,获取到的值可能会不正确。

从SDK的说明来看,onPostCreate 貌似可以实现我们想要的效果。
系统调用到onPostCreate时,Activity应该已经 start-up (彻底跑起来)了。