Skip to content

Blog · Audits, crashes and speed

App hangs and ANRs: causes and fixes

By Shahid Hussain, senior mobile & web engineer ·

A hang is the app freezing while someone waits: taps do nothing and scrolling stops. iPhone calls it a hang. Android calls the long version an ANR, Application Not Responding, and offers to close the app. Both have one cause: the main thread, which draws the screen and handles touches, is busy or blocked. Here’s how to find hangs and ANRs and remove them for good.

What counts

  • iPhone: Apple reports a hang when the main thread doesn’t respond for at least 250 milliseconds. Xcode Organizer’s Hangs report and the Hangs instrument both use that threshold.
  • Android: the system raises an ANR when the app doesn’t respond to an input event within about five seconds, or when a broadcast receiver or service runs too long. Google Play treats a user-perceived ANR rate above 0.47% overall, or 8% on one phone model, as bad behaviour, the same way it treats crashes (Android vitals).

Users feel far shorter freezes than either threshold, so treat the reports as the visible part of the problem.

Where to find them

  • iPhone: Xcode Organizer, Hangs, from users who share diagnostics; MetricKit hang reports, which crash reporters such as Sentry collect; the Hangs track in Instruments while you test.
  • Android: Play Console, Android vitals, ANRs, with stack traces per cluster; Crashlytics’ ANR reports; StrictMode in debug builds, which flags disk and network work on the main thread as it happens.
  • Flutter: heavy Dart code freezes the Flutter UI thread, so frames stop even while the platform’s main thread stays free; that shows up as long frames in the DevTools performance view more than in hang reports. Plugin and platform channel calls that block the main thread do show up as hangs and ANRs.

The usual causes

  • Disk and database work on the main thread: a large settings file read at launch, a database query on the main context, writing preferences synchronously.
  • Waiting on purpose: a network call or background result awaited with a lock, semaphore or blocking call, so the main thread sits idle until something else finishes.
  • Heavy work in the wrong place: parsing a large JSON response, decoding images, sorting or filtering big lists, done on the main thread.
  • Async that isn’t background: in Swift, an async function on the main actor still runs on the main thread; in Flutter, jsonDecode on a large response blocks the UI isolate even inside an async function.
  • Too much at launch: SDK setup and migrations in the first second, which is also when Android is quickest to show an ANR.

How to fix them

  1. Find the frame. The stack trace of the main thread at the moment of the hang names the function. Fix the biggest cluster first.
  2. Move the work off the main thread. Swift concurrency with work that isn’t isolated to the main actor; Kotlin coroutines on Dispatchers.IO or Dispatchers.Default; Flutter’s Isolate.run or compute for heavy Dart work.
  3. Never block on a result. Show a placeholder, load in the background, then update the screen.
  4. Do less up front. Defer setup that the first screen doesn’t need, and cache results that don’t change.
  5. Keep it fixed. Leave StrictMode and the main thread checkers on in debug builds, so the next regression shows up on your desk instead of in a review.

Confirm it in the numbers

Compare the hang rate or ANR rate of the new version against the last one, with a staged rollout so a bad release reaches only a slice of users. A real fix shows up as a drop in the cluster you targeted within days of release.

About the author

Shahid Hussain is a senior mobile & web engineer in Islamabad, Pakistan (UTC+5), with 27+ apps shipped to production in SwiftUI, Flutter, React and Next.js, for Zavi Technology and independent clients.