title: Calling getDecorView for first time locks in the view. How to know if the view is locked?
body: <p>Here is the documentation for Window.getDecorView()
  <a href="http://developer.android.com/reference/android/view/Window.html#getDecorView()" rel="nofollow">http://developer.android.com/reference/android/view/Window.html#getDecorView()</a></p>
  
  <p>As per this, when API is called for first time, various window characterstics are in lock mode. Which is fine. But is there a way to check if the current views in the window are in such lock state or not?
  I'm trying to invoke a method like this:</p>
  
  <pre><code>private void replaceView() {
      Window window = getActivity().getWindow();
      WindowManager wm = getActivity().getWindowManager();
      wm.removeViewImmediate(window.getDecorView());
      wm.addView(window.getDecorView(), window.getAttributes());
  }
  </code></pre>
  
  <p>Now in certain use cases (like orientation change), when the above method is called for the first time, I get a crash.</p>
  
  <pre><code>java.lang.IllegalArgumentException: View=com.android.internal.policy.impl.PhoneWindow$DecorView{eebbc2d V.ED.... R.....ID 0,0-0,0} not attached to window manager
  at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:396)
  at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:322)
  at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
  at com.airwatch.inbox2015.ui.email.MessageComposeFragment.replaceView(MessageComposeFragment.java:619)
  </code></pre>
  
  <p>Is it possible to know by some means that here I'm calling getDecorView() for the first time so removeViewImmediate() API may not work and thereby I can avoid calling that API?</p>
  
  <p>Any help appreciated.</p>