完成对话框和活动
该活动以警报对话框开始
我有一个活动,当我按后退按钮时,仅对话框关闭,
。我想关闭对话框和活动。
如何做到这一点?
I have a activity which start with a alertdialog
when i press back button only dialog get close.
I want to close both dialog and activity.
How to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找可以为Dialog.setOnCancelListener()
在那里你可以调用
finish()
这将完成你的活动
也是如此。You are looking for the
OnCancelListener
that can be set for the Dialog.setOnCancelListener()There you can call
finish()
which will finish yourActivity
, too.这段代码就像一个魅力!
我决定始终接收活动,因为我总是发送 ActivityName.this,而不是仅发送上下文。但后来我收到了上下文。但在这里,我不能仅凭上下文取消活动,我需要该活动。因此,始终发送活动,以便能够从同一活动的外部操作它。
This code works like a charm!!
I had determine to always receive the activity, because I always send ActivityName.this, instead of sending just the context. But then I received the context. But here, I can not cancel the activity with just the context, I need the activity. So, always send the activity, in order to be able to manipulate it from outside the same activity.