Activity has leaked window at alertDialog show() method

前端 未结 6 950
旧时难觅i
旧时难觅i 2020-12-14 16:23

I am getting window leak error at runtime because of using an AlertDialog.

I have pointed out the error line in the code below:

Stacktrace:<

6条回答
  •  囚心锁ツ
    2020-12-14 16:29

    You can also get a WindowLeaked exception if you're not in the UI thread when attempting to show the dialog. Easy fix:

    this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // show dialog here
        }
    });
    

提交回复
热议问题