Common Anr (Application Not Responding) in File Sharing Apps: Causes and Fixes

An Application Not Responding (ANR) error occurs when the main thread (UI thread) is blocked for too long—typically 5 seconds for Android activities. In file sharing applications, the primary culprit

May 04, 2026 · 4 min read · Common Issues

Technical Root Causes of ANRs in File Sharing Apps

An Application Not Responding (ANR) error occurs when the main thread (UI thread) is blocked for too long—typically 5 seconds for Android activities. In file sharing applications, the primary culprit is almost always performing heavy I/O or network operations on the main thread.

Common technical triggers include:

Real-World Impact

For a file sharing app, an ANR is a critical failure. Unlike a minor UI glitch, an ANR freezes the entire interface, forcing the OS to prompt the user to "Close app" or "Wait."

Common ANR Manifestations in File Sharing Apps

ScenarioTriggerManifestation
The Gallery FreezeSelecting 100+ photos for uploadThe UI freezes while the app scans the media store for file paths.
The Upload LockStarting a 1GB file uploadThe "Upload" button remains pressed and the screen becomes unresponsive until the first byte is sent.
The Search HangSearching for a specific file in a large cloud driveThe search bar freezes as the app performs a synchronous query against a local index.
The Permission StallRequesting storage permissions on older Android versionsThe app hangs while waiting for the OS to resolve file system permissions.
The Sync JamSyncing a shared folder with thousands of small filesThe UI locks up while the app iterates through the file list to check for checksum mismatches.
The Network TimeoutAttempting to connect to a peer on a flaky networkThe app freezes because the socket connection attempt is blocking the main thread.

Detecting ANRs: Tools and Techniques

Detecting ANRs manually is difficult because they are often intermittent and device-specific.

Logcat and Traces

When an ANR occurs, Android generates a trace file in /data/anr/traces.txt. Analyze these traces to find the "main" thread and identify the exact method call that is blocking. Look for states like MONITOR (waiting for a lock) or WAITING.

Android Studio Profiler

Use the CPU Profiler to record a trace during a file upload. Look for "long bars" on the main thread. If you see java.io.FileInputStream.read() or okhttp3.Call.execute() on the main thread, you have found your bottleneck.

Autonomous Testing with SUSA

Manual testing often misses edge cases (e.g., uploading a 2GB file while switching networks). SUSA automates this by deploying various user personas to stress-test the app. For example:

SUSA identifies these crashes and ANRs autonomously, providing the exact flow (e.g., Login $\rightarrow$ Search $\rightarrow$ Upload $\rightarrow$ ANR) and generating a report for the engineering team.

How to Fix Common File Sharing ANRs

Fix 1: Move I/O to Background Threads

Problem: Reading file metadata on the main thread.

Fix: Use Kotlin Coroutines with Dispatchers.IO.


// BAD: Blocks UI
val file = File(path).readBytes() 

// GOOD: Offloads to I/O thread
lifecycleScope.launch(Dispatchers.IO) {
    val file = File(path).readBytes()
    withContext(Dispatchers.Main) {
        updateUI(file)
    }
}

Fix 2: Implement Pagination for File Lists

Problem: Loading 5,000 files into a RecyclerView at once.

Fix: Use the Paging Library. Load files in chunks of 20-50. This prevents the main thread from choking on the initial data load.

Fix 3: Asynchronous Network Requests

Problem: Using synchronous .execute() calls for API requests.

Fix: Use .enqueue() in OkHttp or use Retrofit with suspend functions to ensure the network call does not block the UI.

Fix 4: Avoid Main-Thread Database Access

Problem: Querying the local file index on the main thread.

Fix: Use Room's built-in support for Flow or LiveData, which ensures queries run on a background thread and push updates to the UI.

Prevention: Catching ANRs Before Release

To prevent ANRs from reaching production, integrate a rigorous testing pipeline into your CI/CD.

  1. Strict Mode: Enable StrictMode in debug builds. This will crash the app intentionally when you accidentally perform a disk or network operation on the main thread, forcing developers to fix it immediately.
  2. Persona-Based Stress Testing: Use SUSA to simulate diverse user behaviors. Since SUSA explores the app autonomously, it can find "dead buttons" or freezes that occur only when specific sequences of actions are taken (e.g., canceling an upload exactly when the file is 99% complete).
  3. Coverage Analytics: Use SUSA's coverage analytics to ensure every single element—including deep-nested file settings and permission prompts—has been interacted with. This ensures no hidden "blocking" code paths remain.
  4. Automated Regression: Once an ANR is fixed, use SUSA to auto-generate Appium scripts. Integrate these into your GitHub Actions pipeline to ensure the fix doesn't regress in future builds.
  5. CI/CD Integration: Install the SUSA agent (pip install susatest-agent) to run autonomous tests on every PR. If SUSA detects an ANR during its exploration, the build fails, preventing the bug from hitting the Play Store.

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free