Android ANR 问题,AsyncTask
因此,在为我的应用程序创建 AsyncTask 的所有计算并保留 UI 更改直到 onPostExicute 方法之后,我意识到我的应用程序即使只是初始化创建 AsyncTask 的类的所有变量也会出现 ANR。这是我正在讨论的代码:
http://pastebin.com/BB8M9afE (注释中的内容是我正在使用的代码片段)
如果您需要更多代码,我可以发布它。如何防止我的线程类导致 ANR?
代码注释: ColorFloodGame(6,6) 用 math.random() 值填充 int 数组。 GuiThreader 创建一个 ColorFloodGame(6,6) 并将其作为“Play”中的别名,并创建一个执行相同操作的 GUI 驱动程序
So, after making all of my calculations an AsyncTask for my app and leaving the UI changes until the onPostExicute method I realized that my app gets a ANR from even just initializing all of the variables for my class which creates my AsyncTask. Here is the code I'm talking about:
http://pastebin.com/BB8M9afE
(the things in notes are pieces of code I'm playing with)
If you need more of the code, I can post it. How can I keep my threading class from causing an ANR?
Code Notes:
ColorFloodGame(6,6) fills an array of int's with math.random() values. GuiThreader creates a ColorFloodGame(6,6) and makes it an alias of the one in "Play" as well as creating a GUI driver which does the same
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用“adb shell cat /data/anr/traces.txt”查看最后一个ANR的堆栈抓取。列表中的第一个堆栈用于应用程序的主线程,因此它显示 ANR 发生时它正在执行的操作。看看它在哪里,以确定你正在做的事情花了这么长时间。
Use "adb shell cat /data/anr/traces.txt" to see the stack crawls of the last ANR. The first stack in the list is for the main thread of your app, so it shows what it was doing when the ANR happened. Look at where it was to determine what you are doing that takes so long.