Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: View not attached to window manager

Tags:

android

I am getting the following remotely from clients so I don't know what hardware etc they are using.

java.lang.IllegalArgumentException: View not attached to window manager
       at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
       at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
       at android.view.Window$LocalWindowManager.removeView(Window.java:417)
       at android.app.Dialog.dismissDialog(Dialog.java:279)
       at android.app.Dialog.access$000(Dialog.java:72)
       at android.app.Dialog$1.run(Dialog.java:108)
       at android.app.Dialog.dismiss(Dialog.java:263)
       at com..mysite.android.ActivityGame$1.onFinish(ActivityGame.java:154)
       at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:123)
       at android.app.ActivityThread.main(ActivityThread.java:4203)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:521)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)

This is happening because of a ProgressDialog

    progressDialog = new ProgressDialog( this );
    progressDialog.setMessage(getString(R.string.get_ready));
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMax(12);
    progressDialog.show();

    new CountDownTimer(3000, 250) {

         @Override
        public void onTick(long millisUntilFinished) {
             //progressDialog.incrementProgressBy(1);
         }

         @Override
        public void onFinish() {
             progressDialog.dismiss(); //********* ERROR HAPPENS HERE *********
             nextQuestion();
         }
    }.start();

The Activity looks like this in the Manifest.

<activity android:theme="@style/GameTheme" android:name=".ActivityGame" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation"></activity>

So what could this mean? I think it has something to do with the Activity being destroyed then created but as you can see I have the configChanges set correctly.

like image 496
jax Avatar asked Jul 31 '10 12:07

jax


1 Answers

Try:

if (pDialog.isShowing()) {
   pDialog.cancel();
}

in your overridden onDestroy() or onStop() methods.

like image 107
Ajay Avatar answered Oct 26 '22 21:10

Ajay