AppHangs is a problem that can occur in iOS and iPadOS applications, including those developed using Flutter. The term is used to describe situations where an application becomes unresponsive to user input for a period of 250 milliseconds or more.
During an AppHang event, the application seems to freeze, and the user cannot interact with the app's interface. The user interface (UI) of the app effectively "hangs", causing an interruption in the user's interaction with the application. The system may then present the user with a dialog indicating that the application is not responding.
This situation can create a frustrating user experience because it disrupts the user's interaction with the app and can potentially result in data loss if the user's recent actions were not saved before the app became unresponsive. As such, AppHangs are critical issues that significantly impact an application's overall user experience and can discourage users from continuing to use the app.
Similar to ANR events on Android, AppHangs mainly concern responsiveness from the perspective of the user experience. They act as an indicator of something going awry within the app's execution and usually point to areas where lengthy operations are being performed on the main thread, effectively blocking user interactions.
AppHangs can occur due to several reasons in iOS and iPadOS applications, including Flutter apps.
One of the key reasons is the execution of long-running operations on the main thread. When a computationally intensive task runs on the main thread, it can block the thread, making the app unresponsive to user interactions. This can eventually lead to an AppHang situation where the user interface seems to freeze.
Another cause of AppHangs can be deadlocks or race conditions. Deadlocks occur when two or more threads are each waiting for the other to release a resource, resulting in all of them being blocked indefinitely. Race conditions occur when two or more threads access shared data simultaneously, and the result depends on the specific timing of their execution. Both deadlocks and race conditions can lead to situations where the app becomes unresponsive.
Unresponsive UI components are also a common source of AppHangs. When an application's UI thread is blocked, perhaps due to a long-running operation, any UI-related actions such as button presses or scrolling, become unresponsive.
Lastly, slow input/output (I/O) operations can also cause AppHangs. These operations, especially those related to the network or disk, can be time-consuming and if performed on the main thread, can block it for a significant period, resulting in an AppHang.
The issue report provides the stack trace of the main thread, pointing to the line of code that likely triggered the AppHang.
Along with the stack trace, the activity trail - a chronologically ordered list of events that occurred prior to the issue - aids developers in retracing how the user was interacting with the app.