mapbox / mapbox/mapbox-maps-android

ApplicationNotResponding: ANR in LifecycleMonitorAndroid

Open
#2,709 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :beetle:
Dominant language
Kotlin
Stars
578
Forks
161
PR merge metrics
No merged PRs in 30d

Description

Environment

  • Android OS version: 16
  • Devices affected: Samsung SM-F966U1
  • Maps SDK Version: 11.17.1

Observed behavior and steps to reproduce

ANR in LifecycleMonitorAndroid.updateLifecycleState() during activity resume

The app experiences ANRs when any activity resumes, even activities that don't contain a MapView. The ANR occurs in Mapbox's internal lifecycle monitoring.

Stack trace:
io.sentry.android.core.ApplicationNotResponding: ANR
at com.mapbox.common.LifecycleMonitorAndroid.updateLifecycleState(unavailable:0)
at com.mapbox.common.LifecycleMonitorAndroid.access$updateLifecycleState(unavailable:0)
at com.mapbox.common.LifecycleMonitorAndroid$lifecycleServiceCallback$1.onLifecycleStateChanged(unavailable:7)
at com.mapbox.common.LifecycleService.updateLifecycleState(unavailable:13)
at com.mapbox.common.LifecycleService.getLifecycleState(SourceFile:12)
at com.mapbox.common.LifecycleService.registerActivityWithState(unavailable:111)
at com.mapbox.common.LifecycleService.access$registerActivityWithState(unavailable:0)
at com.mapbox.common.LifecycleService$callback$1.onActivityResumed(unavailable:10)
at android.app.Application.dispatchActivityResumed(Application.java:450)
at android.app.Activity.dispatchActivityResumed(Activity.java:1686)
at android.app.Activity.onResume(Activity.java:2287)
at androidx.fragment.app.FragmentActivity.onResume(unavailable:5)
at com.example.app.onboarding.OnboardingActivity.onResume(unavailable:0)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1720)
at android.app.Activity.performResume(Activity.java:9691)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:6162)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:6265)
...

Steps to reproduce:

  1. Initialize Mapbox SDK in Application.onCreate() by setting MapboxOptions.accessToken
  2. Launch any activity (doesn't need to contain a MapView)
  3. Observe ANR during onResume() in Mapbox's lifecycle callback

Expected behavior

LifecycleMonitorAndroid.updateLifecycleState() should not block the main thread and cause ANRs. Lifecycle state updates should be fast and non-blocking, or performed asynchronously.

Notes / preliminary analysis

  • It rarely happens
  • The ANR occurs in activities that have no MapView or map-related functionality
  • Once MapboxOptions.accessToken is set, Mapbox registers ActivityLifecycleCallbacks that run on every activity lifecycle event
  • The updateLifecycleState() method appears to perform blocking operations
  • There is no API available to disable or configure this automatic lifecycle monitoring
  • This affects user experience even when maps are not being displayed

Additional links and references

  • Related to lifecycle monitoring introduced in Mapbox Maps SDK v11
  • Using com.mapbox.maps:android-ndk27:11.17.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at LifecycleMonitorAndroid.updateLifecycleState and trace the ActivityLifecycleCallbacks registration triggered after MapboxOptions.accessToken is set. Reproduce with an Application.onCreate initialization and an activity without a MapView; done means activity resume no longer causes a main-thread ANR.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.