mapbox / mapbox/mapbox-maps-android

State must be at least CREATED to move to DESTROYED, but was INITIALIZED

Open
#2,472 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

## Environment

- Android OS version: any
- Devices affected: any
- Maps SDK Version: 11.5.1 androidx lyfecycle: 2.8.3

## Observed behavior and steps to reproduce

I have a lot of crash from my production app but i can't reproduce it locally.
**I'm not using compose**, i'm using bottom navigation component with backstack saved for each entry using `setRestoreState`, i'm using Material Transition as well when switching screen...
Maybe not a Mapbox issue but a androidx lyfecycle issue using 2.8.3?

![image](https://github.com/user-attachments/assets/3343d0d0-08ae-45d9-a44d-53c3ec6fbd09)

```
Fatal Exception: java.lang.IllegalStateException: State must be at least CREATED to move to DESTROYED, but was INITIALIZED in component com.mapbox.maps.plugin.lifecycle.ViewLifecycleOwner@180f36c
at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.jvm.kt:131)
at androidx.lifecycle.LifecycleRegistry.setCurrentState(LifecycleRegistry.jvm.kt:107)
at com.mapbox.maps.plugin.lifecycle.ViewLifecycleOwner.doOnAttached(ViewLifecycleOwner.kt:73)
at com.mapbox.maps.plugin.lifecycle.ViewLifecycleOwner.(ViewLifecycleOwner.kt:60)
at com.mapbox.maps.plugin.lifecycle.MapboxLifecyclePluginImpl.registerLifecycleObserver(MapboxLifecyclePluginImpl.kt:30)
at com.mapbox.maps.plugin.MapPluginRegistry.onAttachedToWindow(MapPluginRegistry.kt:192)
at com.mapbox.maps.MapController.onAttachedToWindow$sdk_release(MapController.kt:373)
at com.mapbox.maps.MapView.onAttachedToWindow(MapView.kt:135)
at android.view.View.dispatchAttachedToWindow(View.java:21308)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4239)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:4246)
at android.view.ViewGroup.addViewInner(ViewGroup.java:6001)
at android.view.ViewGroup.addView(ViewGroup.java:5777)
at android.view.ViewGroup.addView(ViewGroup.java:5717)
at android.view.ViewGroup.addView(ViewGroup.java:5690)
at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:208)
at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72)
at androidx.transition.Visibility.onDisappear(Visibility.java:429)
at androidx.transition.Visibility.createAnimator(Visibility.java:254)
at androidx.transition.Transition.createAnimators(Transition.java:798)
at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:476)
at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:476)
at androidx.transition.Transition.playTransition(Transition.java:1934)
at androidx.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:300)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1102)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3311)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2201)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9000)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:996)
at android.view.Choreographer.doCallbacks(Choreographer.java:794)
at android.view.Choreographer.doFrame(Choreographer.java:729)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:981)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7948)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
```

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 with the stack-trace entry points in MapboxLifecyclePluginImpl.registerLifecycleObserver, ViewLifecycleOwner.doOnAttached, MapPluginRegistry.onAttachedToWindow, and MapView.onAttachedToWindow. Reproduce the reported bottom-navigation saved-back-stack transition scenario and compare the lifecycle state handling around attachment and destruction. Done means the scenario no longer produces the INITIALIZED-to-DESTROYED exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.