Android: “BadTokenException: Unable to add window; is your activity running?” at showing dialog in PreferenceActivity

前端 未结 6 1093
-上瘾入骨i
-上瘾入骨i 2021-01-30 16:06

I\'d like to ask for some help: In my app, I have only one activity, a PreferenceActivity (don\'t need other, it\'s just a simple background-sync app, so the

6条回答
  •  无人及你
    2021-01-30 16:37

    This is usually caused by your app trying to display a dialog using a previously-finished Activity as a context. Then check that the activity is not closed by some other apps or other triggers before showing the dialog

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

提交回复
热议问题