Performance & Crash Debugging

NetworkOnMainThreadException: Move Blocking Work Off the UI Thread

NetworkOnMainThreadException points to a blocking network operation on the UI thread under Android's applicable checks. Disabling the check does not make the operation responsive; it removes a warning about a real architectural problem.

By Updated 2 min read

Identify the blocking call

Use the crash trace to locate the actual network operation, not only the button handler that called it. A library method with a synchronous API can block even when its name sounds harmless.

Look for connection establishment, response reading and parsing that follows the request.

Move the complete blocking segment

Use an appropriate asynchronous API or coroutine/thread execution model. Keep UI updates on the UI thread, but do not immediately call a blocking wait to retrieve the worker result.

The background-work guidance helps distinguish short in-process work from persistent work that must survive app exit. Not every network request belongs in a persistent worker.

Design cancellation and errors

Event Required behavior
User leaves screen Cancel or detach obsolete UI work
Timeout End loading state and expose retry appropriately
No network Return a meaningful recoverable result
Process ends Persist/retry only if the task's contract requires it

Avoid unbounded retries and duplicate requests after rotation or recomposition.

Keep expensive decoding off the critical path

An asynchronous HTTP call can still cause jank if the callback parses a huge payload or decodes images on the main thread. Measure the whole operation, not just socket activity.

Verify responsiveness under failure

Test slow and unavailable networks while interacting with the UI. Confirm loading indicators, cancellation and retry behavior rather than only checking that a fast request succeeds.

APKLint's code and performance checkers can help flag suspicious patterns, but they do not execute the app's threading model. Keep a trace or reproducible test demonstrating that the UI no longer blocks during the complete network-and-processing flow.

Sources and further reading

  1. Android Developers: Diagnose and fix crashes
  2. Android Developers: Background work overview

Reference review: 22 September 2026. Examples illustrate the workflow; check your installed versions, release artifact and account-specific Console requirements before applying them. This guide is not a claim that APKLint executed your project or verified your private account.

APKLint

Android inspection tools and practical release guides. About APKLint · Report a correction