BadTokenException: Unable to add window, is your activity running?












0















So I'm seeing the error



23  android.view.WindowManager$BadTokenException: Unable to add window -- 
token android.os.BinderProxy@3970aa84 is not valid; is your activity running?
24 at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
25 at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
26 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
27 at android.app.Dialog.show(Dialog.java:298)
28 at com.redacted.timerapp.TimerActivity.u(TimerActivity.java:1177)
29 at com.redacted.timerapp.TimerActivity.onStart(TimerActivity.java:271)


It's being reported in maybe 0.1% of cases (around 10 a day) but I'm unable to reproduce it. The code for the method follows:



private void showDonePrompt() {
if (isFinishing()) return;
Dialog donePrompt = new Dialog(this, R.style.darkDialogDone);
donePrompt.requestWindowFeature(Window.FEATURE_NO_TITLE);
donePrompt.setContentView(R.layout.dialog_dark_done);
donePrompt.setCancelable(false);

Button btnRepeat = (Button)donePrompt.findViewById(R.id.btnRepeat);
btnRepeat.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// some DB operations, etc
donePrompt.dismiss();
}
}
Button btnStop = (Button)donePrompt.findViewById(R.id.btnStop);
btnStop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// some DB operations, etc
donePrompt.dismiss();
}
}

donePrompt.show(); // this is line 1177 which presumably causes it
}


Why is this happening? I check whether the activity isFinishing() and it shouldn't ever try to show the prompt if the activity is not running, right?










share|improve this question



























    0















    So I'm seeing the error



    23  android.view.WindowManager$BadTokenException: Unable to add window -- 
    token android.os.BinderProxy@3970aa84 is not valid; is your activity running?
    24 at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
    25 at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
    26 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
    27 at android.app.Dialog.show(Dialog.java:298)
    28 at com.redacted.timerapp.TimerActivity.u(TimerActivity.java:1177)
    29 at com.redacted.timerapp.TimerActivity.onStart(TimerActivity.java:271)


    It's being reported in maybe 0.1% of cases (around 10 a day) but I'm unable to reproduce it. The code for the method follows:



    private void showDonePrompt() {
    if (isFinishing()) return;
    Dialog donePrompt = new Dialog(this, R.style.darkDialogDone);
    donePrompt.requestWindowFeature(Window.FEATURE_NO_TITLE);
    donePrompt.setContentView(R.layout.dialog_dark_done);
    donePrompt.setCancelable(false);

    Button btnRepeat = (Button)donePrompt.findViewById(R.id.btnRepeat);
    btnRepeat.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    // some DB operations, etc
    donePrompt.dismiss();
    }
    }
    Button btnStop = (Button)donePrompt.findViewById(R.id.btnStop);
    btnStop.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
    // some DB operations, etc
    donePrompt.dismiss();
    }
    }

    donePrompt.show(); // this is line 1177 which presumably causes it
    }


    Why is this happening? I check whether the activity isFinishing() and it shouldn't ever try to show the prompt if the activity is not running, right?










    share|improve this question

























      0












      0








      0








      So I'm seeing the error



      23  android.view.WindowManager$BadTokenException: Unable to add window -- 
      token android.os.BinderProxy@3970aa84 is not valid; is your activity running?
      24 at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
      25 at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
      26 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
      27 at android.app.Dialog.show(Dialog.java:298)
      28 at com.redacted.timerapp.TimerActivity.u(TimerActivity.java:1177)
      29 at com.redacted.timerapp.TimerActivity.onStart(TimerActivity.java:271)


      It's being reported in maybe 0.1% of cases (around 10 a day) but I'm unable to reproduce it. The code for the method follows:



      private void showDonePrompt() {
      if (isFinishing()) return;
      Dialog donePrompt = new Dialog(this, R.style.darkDialogDone);
      donePrompt.requestWindowFeature(Window.FEATURE_NO_TITLE);
      donePrompt.setContentView(R.layout.dialog_dark_done);
      donePrompt.setCancelable(false);

      Button btnRepeat = (Button)donePrompt.findViewById(R.id.btnRepeat);
      btnRepeat.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
      // some DB operations, etc
      donePrompt.dismiss();
      }
      }
      Button btnStop = (Button)donePrompt.findViewById(R.id.btnStop);
      btnStop.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
      // some DB operations, etc
      donePrompt.dismiss();
      }
      }

      donePrompt.show(); // this is line 1177 which presumably causes it
      }


      Why is this happening? I check whether the activity isFinishing() and it shouldn't ever try to show the prompt if the activity is not running, right?










      share|improve this question














      So I'm seeing the error



      23  android.view.WindowManager$BadTokenException: Unable to add window -- 
      token android.os.BinderProxy@3970aa84 is not valid; is your activity running?
      24 at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
      25 at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
      26 at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
      27 at android.app.Dialog.show(Dialog.java:298)
      28 at com.redacted.timerapp.TimerActivity.u(TimerActivity.java:1177)
      29 at com.redacted.timerapp.TimerActivity.onStart(TimerActivity.java:271)


      It's being reported in maybe 0.1% of cases (around 10 a day) but I'm unable to reproduce it. The code for the method follows:



      private void showDonePrompt() {
      if (isFinishing()) return;
      Dialog donePrompt = new Dialog(this, R.style.darkDialogDone);
      donePrompt.requestWindowFeature(Window.FEATURE_NO_TITLE);
      donePrompt.setContentView(R.layout.dialog_dark_done);
      donePrompt.setCancelable(false);

      Button btnRepeat = (Button)donePrompt.findViewById(R.id.btnRepeat);
      btnRepeat.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
      // some DB operations, etc
      donePrompt.dismiss();
      }
      }
      Button btnStop = (Button)donePrompt.findViewById(R.id.btnStop);
      btnStop.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
      // some DB operations, etc
      donePrompt.dismiss();
      }
      }

      donePrompt.show(); // this is line 1177 which presumably causes it
      }


      Why is this happening? I check whether the activity isFinishing() and it shouldn't ever try to show the prompt if the activity is not running, right?







      android






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '17 at 23:56









      TimSimTimSim

      1,15122759




      1,15122759
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You source of isFinishing .



          /**
          * Check to see whether this activity is in the process of finishing,
          * either because you called {@link #finish} on it or someone else
          * has requested that it finished. This is often used in
          * {@link #onPause} to determine whether the activity is simply pausing or
          * completely finishing.
          *
          * @return If the activity is finishing, returns true; else returns false.
          *
          * @see #finish
          */
          public boolean isFinishing() {
          return mFinished;
          }


          So if isFinishing is true , the Activity is destroyed .



          You can try this .



          if(!isFinishing()){
          donePrompt.show();
          }


          or



          if(!hasWindowFocus()){
          donePrompt.show();
          }





          share|improve this answer


























          • The first line in my method is already isFinishing() check. And given that this happens maybe once in a thousand times, I can't really confirm whether your other solution works or not without updating the app and waiting a few days.

            – TimSim
            Nov 20 '17 at 3:24



















          0














          This crash is usually caused by your app trying to display a dialog using a previously-finished Activity as a context.



          For example, this can happen if an Activity triggers an AsyncTask that tries to display a dialog when it is finished, but the user navigates back from the Activity before the task is completed.



          if (!isFinishing()) {
          //showdialog here
          }





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47341137%2fbadtokenexception-unable-to-add-window-is-your-activity-running%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You source of isFinishing .



            /**
            * Check to see whether this activity is in the process of finishing,
            * either because you called {@link #finish} on it or someone else
            * has requested that it finished. This is often used in
            * {@link #onPause} to determine whether the activity is simply pausing or
            * completely finishing.
            *
            * @return If the activity is finishing, returns true; else returns false.
            *
            * @see #finish
            */
            public boolean isFinishing() {
            return mFinished;
            }


            So if isFinishing is true , the Activity is destroyed .



            You can try this .



            if(!isFinishing()){
            donePrompt.show();
            }


            or



            if(!hasWindowFocus()){
            donePrompt.show();
            }





            share|improve this answer


























            • The first line in my method is already isFinishing() check. And given that this happens maybe once in a thousand times, I can't really confirm whether your other solution works or not without updating the app and waiting a few days.

              – TimSim
              Nov 20 '17 at 3:24
















            0














            You source of isFinishing .



            /**
            * Check to see whether this activity is in the process of finishing,
            * either because you called {@link #finish} on it or someone else
            * has requested that it finished. This is often used in
            * {@link #onPause} to determine whether the activity is simply pausing or
            * completely finishing.
            *
            * @return If the activity is finishing, returns true; else returns false.
            *
            * @see #finish
            */
            public boolean isFinishing() {
            return mFinished;
            }


            So if isFinishing is true , the Activity is destroyed .



            You can try this .



            if(!isFinishing()){
            donePrompt.show();
            }


            or



            if(!hasWindowFocus()){
            donePrompt.show();
            }





            share|improve this answer


























            • The first line in my method is already isFinishing() check. And given that this happens maybe once in a thousand times, I can't really confirm whether your other solution works or not without updating the app and waiting a few days.

              – TimSim
              Nov 20 '17 at 3:24














            0












            0








            0







            You source of isFinishing .



            /**
            * Check to see whether this activity is in the process of finishing,
            * either because you called {@link #finish} on it or someone else
            * has requested that it finished. This is often used in
            * {@link #onPause} to determine whether the activity is simply pausing or
            * completely finishing.
            *
            * @return If the activity is finishing, returns true; else returns false.
            *
            * @see #finish
            */
            public boolean isFinishing() {
            return mFinished;
            }


            So if isFinishing is true , the Activity is destroyed .



            You can try this .



            if(!isFinishing()){
            donePrompt.show();
            }


            or



            if(!hasWindowFocus()){
            donePrompt.show();
            }





            share|improve this answer















            You source of isFinishing .



            /**
            * Check to see whether this activity is in the process of finishing,
            * either because you called {@link #finish} on it or someone else
            * has requested that it finished. This is often used in
            * {@link #onPause} to determine whether the activity is simply pausing or
            * completely finishing.
            *
            * @return If the activity is finishing, returns true; else returns false.
            *
            * @see #finish
            */
            public boolean isFinishing() {
            return mFinished;
            }


            So if isFinishing is true , the Activity is destroyed .



            You can try this .



            if(!isFinishing()){
            donePrompt.show();
            }


            or



            if(!hasWindowFocus()){
            donePrompt.show();
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 17 '17 at 1:33

























            answered Nov 17 '17 at 1:25









            KeLiuyueKeLiuyue

            6,00341329




            6,00341329













            • The first line in my method is already isFinishing() check. And given that this happens maybe once in a thousand times, I can't really confirm whether your other solution works or not without updating the app and waiting a few days.

              – TimSim
              Nov 20 '17 at 3:24



















            • The first line in my method is already isFinishing() check. And given that this happens maybe once in a thousand times, I can't really confirm whether your other solution works or not without updating the app and waiting a few days.

              – TimSim
              Nov 20 '17 at 3:24

















            The first line in my method is already isFinishing() check. And given that this happens maybe once in a thousand times, I can't really confirm whether your other solution works or not without updating the app and waiting a few days.

            – TimSim
            Nov 20 '17 at 3:24





            The first line in my method is already isFinishing() check. And given that this happens maybe once in a thousand times, I can't really confirm whether your other solution works or not without updating the app and waiting a few days.

            – TimSim
            Nov 20 '17 at 3:24













            0














            This crash is usually caused by your app trying to display a dialog using a previously-finished Activity as a context.



            For example, this can happen if an Activity triggers an AsyncTask that tries to display a dialog when it is finished, but the user navigates back from the Activity before the task is completed.



            if (!isFinishing()) {
            //showdialog here
            }





            share|improve this answer






























              0














              This crash is usually caused by your app trying to display a dialog using a previously-finished Activity as a context.



              For example, this can happen if an Activity triggers an AsyncTask that tries to display a dialog when it is finished, but the user navigates back from the Activity before the task is completed.



              if (!isFinishing()) {
              //showdialog here
              }





              share|improve this answer




























                0












                0








                0







                This crash is usually caused by your app trying to display a dialog using a previously-finished Activity as a context.



                For example, this can happen if an Activity triggers an AsyncTask that tries to display a dialog when it is finished, but the user navigates back from the Activity before the task is completed.



                if (!isFinishing()) {
                //showdialog here
                }





                share|improve this answer















                This crash is usually caused by your app trying to display a dialog using a previously-finished Activity as a context.



                For example, this can happen if an Activity triggers an AsyncTask that tries to display a dialog when it is finished, but the user navigates back from the Activity before the task is completed.



                if (!isFinishing()) {
                //showdialog here
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 15 hours ago

























                answered 20 hours ago









                Las LemieuxLas Lemieux

                264




                264






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47341137%2fbadtokenexception-unable-to-add-window-is-your-activity-running%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Callistus III

                    Plistias Cous

                    Index Sanctorum