“android.view.WindowManager$BadTokenException: Unable to add window” on buider.show()

前端 未结 10 926
忘掉有多难
忘掉有多难 2020-11-22 10:43

From my main activity, I need to call an inner class and in a method within the class, I need to show AlertDialog. After dismissing it, when the OK

10条回答
  •  佛祖请我去吃肉
    2020-11-22 11:18

    I had dialog showing function:

    void showDialog(){
        new AlertDialog.Builder(MyActivity.this)
        ...
        .show();
    }
    

    I was getting this error and i just had to check isFinishing() before calling this dialog showing function.

    if(!isFinishing())
        showDialog();
    

提交回复
热议问题