@ TargetApi ( Build . VERSION_CODES . JELLY_BEAN ) public static void detach ( Activity activity , ViewTreeObserver . OnGlobalLayoutListener l ) { ViewGroup contentView = activity . findViewById ( android . R . id . content ) ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . JELLY_BEAN ) { contentView . getViewTreeObserver ( ) . removeOnGlobalLayoutListener ( l ) ; } else { //noinspection deprecation contentView . getViewTreeObserver ( ) . removeGlobalOnLayoutListener ( l ) ; } }
Remove the OnGlobalLayoutListener from the activity root view