Android - 无法通过应用内计费关闭 AlertDialog
我在使用用于启动应用内购买的 AlertDialog 时遇到问题。当用户点击“购买”按钮时,应用内购买将按预期触发,但 AlertDialog 不会关闭。然后,当应用程序内购买完成时,程序返回到我的应用程序,但 AlertDialog 仍然打开。
如果我注释掉 buyCard() 函数,AlertDialog 将关闭。知道为什么当涉及应用内计费时 AlertDialog 没有关闭吗?
final CharSequence[] items = {"Buy","Close"};
AlertDialog.Builder builder = new AlertDialog.Builder(Card.this);
builder.setTitle("Want to Buy?");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(item == 0) { // BUY THE ITEM
dialog.dismiss();
buyCard();
} else if (item == 1) { // Don't Buy
dialog.dismiss();
}
}
});
AlertDialog alert = builder.create();
alert.show();
I am having a problem with an AlertDialog that I am using to initiate an In-App Purchase. When the user taps the "Buy" button, the In-App Purchase fires as expected, but the AlertDialog does not close. Then, when the In-App Purchase finishes, the program returns to my app but the AlertDialog is still open.
If I comment out the buyCard() function, the AlertDialog will close. Any idea why the AlertDialog is not closing when the In-App Billing is involved?
final CharSequence[] items = {"Buy","Close"};
AlertDialog.Builder builder = new AlertDialog.Builder(Card.this);
builder.setTitle("Want to Buy?");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if(item == 0) { // BUY THE ITEM
dialog.dismiss();
buyCard();
} else if (item == 1) { // Don't Buy
dialog.dismiss();
}
}
});
AlertDialog alert = builder.create();
alert.show();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我确信这个问题早已得到解决,但可能的解决方案是将buyCard();移至dialog.dismiss();上方
所以,就像这样:
原因是,对话框无法运行
buyCard();
行,因为您已经将其关闭。有点像尝试在return
语句之后运行代码。I'm sure this question has long been figured out, but the probable solution would be to move
buyCard();
to abovedialog.dismiss();
So, like this:
Reason being, the dialog can't run the
buyCard();
line since you've already dismissed it. Kind of like trying to run code after areturn
statement.