java - 哪些 Android 组件和哪些方法可能会出现应用程序无响应问题?为什么?

标签 java android performance

它适用于服务、 Activity 、 fragment 等。是不是只有在UI线程中进行一些繁重操作的情况下才会出现?

也只是想知道 - 这些组件的哪种方法可以抛出/增加 ANR?

最佳答案

In Android, the system guards against applications that are insufficiently responsive for a period of time by displaying a dialog that says your app has stopped responding. At this point, your app has been unresponsive for a considerable period of time so the system offers the user an option to quit the app

Generally, the system displays an ANR if an application cannot respond to user input. For example, if an application blocks on some I/O operation (frequently a network access) on the UI thread so the system can't process incoming user input events. Or perhaps the app spends too much time building an elaborate in-memory structure or computing the next move in a game on the UI thread. It's always important to make sure these computations are efficient, but even the most efficient code still takes time to run.

In Android, application responsiveness is monitored by the Activity Manager and Window Manager system services. Android will display the ANR dialog for a particular application when it detects one of the following conditions: No response to an input event (such as key press or screen touch events) within 5 seconds. A BroadcastReceiver hasn't finished executing within 10 seconds.

挑选出与您的问题相关的部分。 但如需了解更多信息,请查看android doc我从哪里得到这个。

当您在主线程上运行长时间运行的操作(例如网络)时,通常会发生 ANR。

关于java - 哪些 Android 组件和哪些方法可能会出现应用程序无响应问题?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151066/

相关文章:

使用三星设备的 Android 指纹扫描

java - 为什么避免 boolean 实例化是个好主意?

java - 新代码行的代码覆盖质量关卡

java - 使用 fastJSON 反序列化零件数据失败

java - 从 perl 调用 java 类

java - 使用 PendingIntent 停止服务

java - PostgreSQL - quartz JDBC-JobStoreTX - getTriggersForJob - ArrayIndexOutOfBoundsException

android - 在堆栈跟踪中没有应用程序代码的 ListView 中滚动时的 IndexOutOfBounds

c# - 生成 CPU 缓存未命中时的性能

java - 检查 Oracle 数据库性能的工具