title: OnGlobalLayoutListener: deprecation and compatibility
body: <p>I have to use an <code>OnGlobalLayoutListener</code> object and then to remove the listener, I had a problem with deprecated methods that I resolve with following code.</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
      final LinearLayout llTotal = (LinearLayout) findViewById(R.id.mmc_ll);
      ViewTreeObserver vto = llTotal.getViewTreeObserver();
      if(vto.isAlive()){
          vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                  //
                  // mycode
                  //
                  if (Build.VERSION.SDK_INT&lt;16) {
                      removeLayoutListenerPre16(llTotal.getViewTreeObserver(),this);
                  } else {
                      removeLayoutListenerPost16(llTotal.getViewTreeObserver(), this);
                  }
              } 
          });
      }
      super.onCreate(savedInstanceState);
  }
  
  @SuppressWarnings("deprecation")
  private void removeLayoutListenerPre16(ViewTreeObserver observer, OnGlobalLayoutListener listener){
      observer.removeGlobalOnLayoutListener(listener);
  }
  
  @TargetApi(16)
  private void removeLayoutListenerPost16(ViewTreeObserver observer, OnGlobalLayoutListener listener){
      observer.removeOnGlobalLayoutListener(listener);
  }
  </code></pre>
  
  <p>Is it correct? There is a better way to handle compatibility?</p>
  
  <p>Running the code in emulator with API 10 I have the following warning in LogCat</p>
  
  <pre><code>04-24 09:30:12.565: I/dalvikvm(471): Could not find method android.view.ViewTreeObserver.removeOnGlobalLayoutListener, referenced from method com.my.project.ActivityHome.removeLayoutListenerPost16
  04-24 09:30:12.565: W/dalvikvm(471): VFY: unable to resolve virtual method 2950: Landroid/view/ViewTreeObserver;.removeOnGlobalLayoutListener (Landroid/view/ViewTreeObserver$OnGlobalLayoutListener;)V
  </code></pre>
  
  <p>Can I ignore them of I have to fix in some way?</p>