Skip to content
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

Exception java.lang.IllegalStateException: This ViewTreeObserver is not alive, call getViewTreeObserver() again #133

Closed
wangjingyang opened this issue May 23, 2024 · 5 comments · Fixed by #134
Labels
bug Something isn't working

Comments

@wangjingyang
Copy link

Description

Exception java.lang.IllegalStateException: This ViewTreeObserver is not alive, call getViewTreeObserver() again
at android.view.ViewTreeObserver.checkIsAlive (ViewTreeObserver.java:984)
at android.view.ViewTreeObserver.removeOnDrawListener (ViewTreeObserver.java:759)
at com.posthog.android.replay.PostHogReplayIntegration.cleanSessionState$lambda$6$lambda$5 (PostHogReplayIntegration.kt:253)
at com.posthog.android.replay.PostHogReplayIntegration.$r8$lambda$Fo0KroR9KoezO0ojDFIMQW4ICps
at com.posthog.android.replay.PostHogReplayIntegration$$ExternalSyntheticLambda2.run
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:226)
at android.os.Looper.loop (Looper.java:313)
at android.app.ActivityThread.main (ActivityThread.java:8663)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

@marandaneto
Copy link
Member

@wangjingyang which version of the SDK are you using? is it crashing the app or just logging on to Logcat?

@marandaneto marandaneto added bug Something isn't working Replay labels May 24, 2024
@wangjingyang
Copy link
Author

v3.2.2
Yes, it crashed and was reported to firebase。
I think the code should be like this:

private fun cleanSessionState(
     view: View,
     status: ViewTreeSnapshotStatus,
 ) {
     view.viewTreeObserver?.let { viewTreeObserver ->
         mainHandler.handler.post {
             if (viewTreeObserver.isAlive) { // Move this line of code inside the post code block
                 viewTreeObserver.removeOnDrawListener(status.listener)
             }
         }
     }
     view.phoneWindow?.let { window ->
         window.touchEventInterceptors -= onTouchEventListener
     }

     decorViews.remove(view)
 }

@marandaneto
Copy link
Member

@wangjingyang I have a draft PR already https://github.com/PostHog/posthog-android/pull/134/files
Thanks for reporting it, sorry about that.
Not sure if it crashed tho, Since cleanSessionState is called by uninstall and the uninstall already swallows exceptions.
Same for onRootViewsChangedListener.
Maybe it'd crash because when we do mainHandler.handler.post, it's in a different scope so I have added another try catch anyway.

@wangjingyang
Copy link
Author

When will the new version be updated?

@marandaneto
Copy link
Member

Once https://github.com/PostHog/posthog-android/actions/runs/9219736666 finishes running it'll be published, usually maven central has a few minutes delay as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants