gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:44:50 24 4
gpt4 key购买 nike

它适用于服务、 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com