Skip to content

ANR based on ApplicationExitInfo #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 72 commits into from
Jun 18, 2025
Merged

ANR based on ApplicationExitInfo #166

merged 72 commits into from
Jun 18, 2025

Conversation

BartoszLitwiniuk
Copy link
Collaborator

@BartoszLitwiniuk BartoszLitwiniuk commented Mar 18, 2025

​This pull request introduces a new method for detecting Application Not Responding (ANR) events by utilizing the ApplicationExitInfo API, available in Android API level 30 (Android 11) and above. By leveraging this API, the Backtrace Android SDK can more accurately and efficiently detect ANR events, enhancing the reliability of application monitoring.

Key Changes:

  • ANR Detection Enhancement: Implemented ANR detection based on ApplicationExitInfo, improving the accuracy of ANR reporting on devices running Android 11 and later.​

  • Backward Compatibility: Ensured that the existing ANR detection mechanisms remain functional for devices running Android versions prior to 11, maintaining broad compatibility across Android versions.​

  • Code Refactoring: Refactored relevant components to integrate the new ANR detection method seamlessly, enhancing code maintainability and clarity.​

Benefits:
This update provides developers with more precise ANR detection on newer Android devices, leading to better diagnostics and application performance insights. The integration of ApplicationExitInfo allows for a more standardized approach to ANR detection, aligning with modern Android development practices.​

How It Works
Now, users can choose their preferred ANR detection method. The Threshold method detects ANRs by monitoring the main application thread for freezes, while the ApplicationExit method relies on events from the Android API.

When using the ApplicationExit method, a background thread is spawned to process ANR events. This thread retrieves all recorded events, checks the last reported timestamp stored in SharedPreferences, and evaluates each event's type and timestamp. If an event has the type REASON_CRASH and its timestamp is more recent than the last recorded one, it is sent to the Backtrace API. Once sent, the timestamp is updated in SharedPreferences. After processing all events, the background thread terminates.

Docs PR: saucelabs/sauce-docs#3160
Example ANR error: https://yolo.sp.backtrace.io/api/share/1e88nzW5jOx3njx2gVZdooX3
image
image

Bartosz Litwiniuk added 2 commits May 4, 2025 20:13
# Conflicts:
#	backtrace-library/build.gradle
@BartoszLitwiniuk BartoszLitwiniuk merged commit 739129d into master Jun 18, 2025
1 check passed
@BartoszLitwiniuk BartoszLitwiniuk deleted the anr-app-exit branch June 18, 2025 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants