title: Android - Error - IllegalArgumentException: Window type can not be changed after the window is added
body: <p>I am debugging an android app (which was unfortunately written by someone else). The app has a splash activity which lasts for 1 second and then the transitions to a landing page activity using an intent. The app was running fine until I noticed that the targetSDKVersion was not set in the manifest file. I set it to 18. And then when I run the app in the emulator, the app crashes and I see the following error in logcat: </p>
  
  <pre><code>10-24 06:14:26.840: E/AndroidRuntime(2457): FATAL EXCEPTION: main
  10-24 06:14:26.840: E/AndroidRuntime(2457): java.lang.IllegalArgumentException: Window type can not be changed after the window is added.
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Parcel.readException(Parcel.java:1435)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Parcel.readException(Parcel.java:1385)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.IWindowSession$Stub$Proxy.relayout(IWindowSession.java:835)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl.relayoutWindow(ViewRootImpl.java:5034)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1399)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer.doFrame(Choreographer.java:532)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Handler.handleCallback(Handler.java:730)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Handler.dispatchMessage(Handler.java:92)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.os.Looper.loop(Looper.java:137)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at java.lang.reflect.Method.invokeNative(Native Method)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at java.lang.reflect.Method.invoke(Method.java:525)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  10-24 06:14:26.840: E/AndroidRuntime(2457):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The app crashes immediately after showing the splash screen and before the landing page activity is loaded. The following blocks show relevant code blocks from the splash activity.</p>
  
  <h2>Splash Activity</h2>
  
  <pre><code>private Thread mSplashThread;    
  @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.splash);
      final SplashScreenActivity sPlashScreen = this;   
          mSplashThread =  new Thread(){
  
  @Override
          public void run(){
          try {
              synchronized(this){
                  // Wait given period of time or exit on touch
                  wait(1000);
              }
          }
          catch(InterruptedException ex){                    
          }
  
          finish();
  
          // Run next activity
          Intent intent = new Intent();
          intent.setClass(sPlashScreen, LandingPageActivity.class);
          startActivity(intent);                 
          }
      };
      mSplashThread.start();        
      }
  
  @Override
  public boolean onTouchEvent(MotionEvent evt)
  {
      if(evt.getAction() == MotionEvent.ACTION_DOWN)
      {
      try{
          synchronized(mSplashThread){
              mSplashThread.notifyAll();
              }
      }
      catch (IllegalArgumentException e){
          Log.v("This is it", e.getCause().getMessage());
      }
  }
  return true;
  }
  </code></pre>
  
  <p>Now in all my research to debug this issue I found suggestions to check for following code piece but I don't have anything like this in my app:</p>
  
  <pre><code>@Override
      public void onAttachedToWindow()
      {  
          this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
          super.onAttachedToWindow();  
      }
  </code></pre>