Bad window token, you cannot show a dialog before an Activity is created or after it's hidden

前端 未结 5 2033
有刺的猬
有刺的猬 2021-02-03 22:02

I am using an AppIntro library in my app.

It has 3 slides. I want to ask the user something when the third slide is shown. To achieve that I am using material dialogs b

5条回答
  •  不思量自难忘°
    2021-02-03 22:47

    This can be resolved by confirming that current Activity hasWindowFocus because when you get the context in the fragment, instead of exactly which Activity it is, it might not have windowFocus :

    if (((Activity) mContext).hasWindowFocus()) {
            mDialog.show();
    }
    

提交回复
热议问题