問(wèn)題描述
我在我的應(yīng)用程序中使用 AppIntro 庫(kù).
I am using an AppIntro library in my app.
它有 3 張幻燈片.當(dāng)顯示第三張幻燈片時(shí),我想問(wèn)用戶一些事情.為了實(shí)現(xiàn)這一點(diǎn),我正在使用 afollestad 的材質(zhì)對(duì)話框.
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 by afollestad.
我在 AppIntro Activity 中的代碼如下所示:
My code in the AppIntro Activity looks like that:
@Override
public void onNextPressed() {
if(this.pager.getCurrentItem() == 2) {
MaterialDialog dialog = new MaterialDialog.Builder(getApplicationContext())
.title("QR Code scannen")
.content("M?chtest du den QR Code scannen oder selbst eingeben?")
.positiveText("eingeben")
.negativeText("scannen")
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Intent intent = new Intent(getApplicationContext(), RegistrationActivity.class);
startActivity(intent);
}
})
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
// TODO
}
})
.show();
}
}
運(yùn)行應(yīng)用程序當(dāng)我滑到第三張幻燈片時(shí)出現(xiàn)以下問(wèn)題:
Running the App I get the following issue when I slide to the third slide:
com.afollestad.materialdialogs.MaterialDialog$DialogException:
Bad window token, you cannot show a dialog before an Activity is created or after it's hidden.
at com.afollestad.materialdialogs.MaterialDialog.show(MaterialDialog.java:1328)
at com.afollestad.materialdialogs.MaterialDialog$Builder.show(MaterialDialog.java:1317)
at com.ads.adstimer.fragment.Registration.RegistrationActivity.onNextPressed(RegistrationActivity.java:64)
at com.github.paolorotolo.appintro.AppIntro$2.onClick(AppIntro.java:118)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21153)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
我真的不明白這個(gè)問(wèn)題.因?yàn)?AppIntro Activity 已經(jīng)加載,我希望它在顯示特定片段時(shí)顯示一個(gè)對(duì)話框.
I do not really understand the problem. Because the AppIntro Activity is already loaded and I expect it to show a dialog when a specific fragment is shown.
如何實(shí)現(xiàn)在顯示特定幻燈片時(shí)顯示對(duì)話框?
How can I achieve to show a dialog when a specific slide is shown?
推薦答案
MaterialDialog dialog = new MaterialDialog.Builder(getApplicationContext())
我想你需要在這里傳遞 Activity
實(shí)例,而不是應(yīng)用程序上下文.
I suppose you need to pass the Activity
instance here, not the application context.
這篇關(guān)于錯(cuò)誤的窗口令牌,您無(wú)法在創(chuàng)建 Activity 之前或隱藏之后顯示對(duì)話框的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!