Merge "Optimize onAttachedTo/onDetachedFromWindow"