关于“强制关闭/等待”通知
我有一个带有列表视图的应用程序,可以动态下载图像。它们是非常小的图像,下载后会被存储。但是,如果用户的连接速度非常慢(我的意思是非常慢),它就会滞后,并且会提示用户“强制关闭还是等待?”对话。
我想知道我是否可以在用户收到通知之前捕获此问题,这将使我能够终止我的线程,抛出我自己的自定义对话框并按照我想要的方式处理它。
这可能吗?
I have an app with a list view that downloads images on the fly. They are very small images and they are being stored after downloading. However, if the user has a very slow connection (and I mean very slow), it lags and the user is prompted with a "Force Close or Wait?" dialog.
I am wondering if I can catch this before the user get's notified, which would enable me to kill my thread, throw my own custom dialog up and handle it how I want.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将收到
ANR(应用程序未响应)
对话框,因为您正在阻塞 UI 线程。这很糟糕!在单独的线程(如AsyncTask
)上执行所有长时间运行的任务(例如网络或文件 IO)。您可以使用 严格模式 来检测您在何处滥用 UI 线程。
建议您寻找 Painless Threading 和 多线程
You are getting an
ANR (application not responding)
dialog because you are blocking the UI thread. THIS IS BAD! Do all your long running tasks (like network or file IO) on a separate thread sayAsyncTask
.You can use Strict Mode to detect where you are misusing the UI thread.
Suggest you to look for Painless Threading and Multi-Threading
听起来您正在 UI 线程上进行下载。这与建议的做法相反,并且从 Honeycomb 开始,将引发异常。请参阅文章Painless Threading,了解将网络活动移出 UI 的方法线。
It sounds like you are doing your downloads on the UI thread. This is contrary to recommended practice and, as of Honeycomb, will throw an exception. See the article Painless Threading for ways to move your network activity off the UI thread.
我建议您可能不想在 UIThread 上下载图像。您可能应该将图像的加载移至后台线程,这样您就不会首先收到 ANR。
您可以考虑使用 AsyncTask 或类似的工具来完成这项工作,这样您就不必自己编写线程同步代码。
I would suggest that you probably dont want to be downloading images on the UIThread. You probably should move the loading of the images onto a background thread so that you dont get the ANR in the first place.
You could look at using AsyncTask or similar to do the work so you dont have to write the thread sync code yourself.