View.addOnAttachStateChangeListener这在开发中仍是比较常见的方法,view的依附变化回调,可是在什么时机回调是本文详解的重点。blog
- onViewAttachedToWindow()
在ActivityThread源码中能够看到,是在onResume以后,WindowManager.addView()方法会依次遍历View的onViewAttachedToWindow();
- onViewDetachedFromWindow() 1)父级View调用removeView()方法 2)Activity或fregment销毁时