当“搜索”打开时,进度对话框消失手机上的按键被按下
在活动的 onCreate 中,我们连接到远程系统并下载数据。我们一直向用户显示一个可取消的 ProgressDialog。下载是使用 AsyncTask 完成的。在 preExecute() 中,我们显示对话框,在 postExecute() 中我们关闭它。
问题是,当下载正在进行并且显示 ProgressDialog 时,如果用户按下设备上的“搜索”按钮,ProgressDialog 就会消失。后台线程仍在运行。
是什么原因导致这种行为?如何避免这种情况?
请帮忙。
谢谢。
In the onCreate of an activity we are connecting to a remote system and downloading data. We display a cancellable ProgressDialog to the user all this time. Download is done using AsyncTask. In preExecute(), we show the dialog and in postExecute() we dismiss it.
Problem is that when the download is in progress and ProgressDialog on display, if the user presses the "search" button on the device, the ProgressDialog disappears. The background thread is still running.
What cause this behavior? How can this be avoided?
Please help.
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以解决这个问题(注意我把它放在对话框生成器上):
也许甚至可以获取正按钮和负按钮的按下,并且仅处理这些,对于任何其他键返回 true 。如果您能弄清楚这一点,我会很好奇...
PS:我读到对话框中还有更多“漏洞”,即您可以在不点击对话框本身上的任何按钮的情况下摆脱它。这显然是其中之一。有人知道其他人吗?
PS2:这似乎重复了 Prevent当我单击搜索按钮(Android)时,ProgressDialog 被关闭
This should fix that works (notice I put it on the dialog builder):
Maybe it's even possible to grab the positive and negative button presses, and only handle these, return true for any other keys. Would be curious if you can figure that out...
PS: I read there are more "holes" in the dialog, i.e you can get rid of it without hitting any buttons on the dialog itself. This was apparently one. Does anybody know of any others?
PS2: this seems a repeat of Prevent ProgressDialog from being dismissed when I click the search button (Android)