firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

Random crash related with In-App Messaging

Open wtopolski opened this issue 8 years ago • 37 comments

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 3.2.1
  • Firebase Component: In-App Messaging
  • Component version: 17.0.3

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

I set up campaign which should show "modal" triggered by "on_foreground" event. From time to time I receive below crash. There are no reasonable reproduce steps. It just happens. I have found that the same issue was reported on picasso project: https://github.com/square/picasso/issues/2002

11-02 12:43:13.888 27311-27311/pl.allegro.sale.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: pl.allegro.sale.debug, PID: 27311
android.view.WindowManager$BadTokenException: Unable to add window – token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:849)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:337)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at com.google.firebase.inappmessaging.display.internal.FiamWindowManager.show(com.google.firebase:firebase-inappmessaging-display@@17.0.3:62)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$5.onSuccess(com.google.firebase:firebase-inappmessaging-display@@17.0.3:385)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.loadNullableImage(com.google.firebase:firebase-inappmessaging-display@@17.0.3:418)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.inflateBinding(com.google.firebase:firebase-inappmessaging-display@@17.0.3:324)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.access$400(com.google.firebase:firebase-inappmessaging-display@@17.0.3:73)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$2.run(com.google.firebase:firebase-inappmessaging-display@@17.0.3:267)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

wtopolski avatar Nov 05 '18 13:11 wtopolski

@MeghaB can you take a look pls?

/assign @MeghaB

vkryachko avatar Nov 05 '18 14:11 vkryachko

cc @JasonAHeron ... I knew the day would come when we'd have to reckon with FiamWindowManager

samtstern avatar Nov 05 '18 16:11 samtstern

yup, thanks @vkryachko!

MeghaB avatar Nov 05 '18 17:11 MeghaB

Same crash detected by Crashlytics in my app. I tried to reproduce it, but I found nothing so far. I tried to finish my Activity during IAM fetch, but it just lost the message. No crashes. Do you have any update about it?

Please feel free to contact me if you need more information. I'd like to help you.

ericksprengel avatar Jan 02 '19 16:01 ericksprengel

Facing same issue with inapp messaging, it crashes to 2-3 % of users, can we know any workaround to handle this crash atleast so that we can graciously handle it?

Sunkari16 avatar Jan 05 '19 11:01 Sunkari16

@MeghaB any info about this crash , we are seeing a lot of users are impacted and this is becoming a road block for us. is there something we can do on our end to handle this

Sunkari16 avatar Jan 07 '19 05:01 Sunkari16

Logs

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running? at android.view.ViewRootImpl.setView(ViewRootImpl.java:562) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85) at com.google.firebase.inappmessaging.display.internal.FiamWindowManager.show(SourceFile:62) at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$5.onSuccess(SourceFile:385) at com.squareup.picasso.ImageViewAction.complete(SourceFile:51) at com.squareup.picasso.Picasso.deliverAction(SourceFile:558) at com.squareup.picasso.Picasso.complete(SourceFile:510) at com.squareup.picasso.Picasso$1.handleMessage(SourceFile:117) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5357) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:952) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)

please help it's crashing many of our users. or tell us some workaround till then. Can we control how we start inapp in activity only

worstkiller avatar Jan 07 '19 14:01 worstkiller

plz solve the crash :(

mouness2020 avatar Jan 15 '19 08:01 mouness2020

I'm also facing the issue, I'm wondering if there's a way to catch the error at least.

glocci avatar Jan 18 '19 00:01 glocci

i guess it happens because of splash activity close while Dialog is opening

lucarocchi avatar Jan 27 '19 09:01 lucarocchi

From my investigation this is due to the activity window not being displayed while the FIAM tries to render using view.WindowManager. If my understanding is correct the root cause is because the view we are adding is not natively activity aware. Looking at other solutions seems to indicate that we might be able to delay our rendering until all activity lifecycle events have fired; something like the solution here. The main difficulty is reproducing the issue. Has anyone here been able to figure out a way to consistently reproduce this?

JasonAHeron avatar Jan 28 '19 17:01 JasonAHeron

Alright folks, I have a potential fix for this issue that should be available in the next release. Since we can't easily reproduce it will be up to you folks to let me know if things improve. I'll check back in here when the release is available.

JasonAHeron avatar Jan 28 '19 23:01 JasonAHeron

another stack trace from Crashlytics, hope it helps

Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
       at android.view.ViewRootImpl.setView(ViewRootImpl.java:890)
       at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:377)
       at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:97)
       at com.google.firebase.inappmessaging.display.internal.zzg.zza(com.google.firebase:firebase-inappmessaging-display@@17.0.1:62)
       at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$5.onSuccess(com.google.firebase:firebase-inappmessaging-display@@17.0.1:372)
       at com.squareup.picasso.ImageViewAction.complete(ImageViewAction.java:51)
       at com.squareup.picasso.Picasso.deliverAction(Picasso.java:558)
       at com.squareup.picasso.Picasso.complete(Picasso.java:510)
       at com.squareup.picasso.Picasso$1.handleMessage(Picasso.java:117)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6776)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

lucarocchi avatar Jan 30 '19 07:01 lucarocchi

@JasonAHeron I think in reading this too quickly we skipped over the mentions of picasso. Picasso is our async image loading library so I think what happens is that when the picasso request finishes the Activity is either not ready or already dead (we fire-and-forget picasso).

With a similar library, Glide, I have solved this by using view.getContext() of the target View as the Context for the image loading, rather than the Activity. Maybe that will work here too?

https://github.com/firebase/firebase-android-sdk/blob/master/firebase-inappmessaging-display/src/main/java/com/google/firebase/inappmessaging/display/FirebaseInAppMessagingDisplay.java#L324

samtstern avatar Feb 05 '19 06:02 samtstern

plz solve the crash :(

gungoren avatar Feb 15 '19 07:02 gungoren

4 months.... i think we will soon be celebrating happy aniversary to this issue

bolds07 avatar Mar 13 '19 03:03 bolds07

So... Is it going to be fixed? We cannot use in-app messages because of it - it causes mass crashes in our app and we cannot even handle it.

As far as I understood, the problem is with Picasso - maybe you should switch to Glide? Or fix the issue by adding a simple null check for activity?

Ein6tein avatar Mar 14 '19 08:03 Ein6tein

Any news regarding this crash?

GrizzlyDoc avatar May 08 '19 10:05 GrizzlyDoc

Is there any progress?

fvermeulen avatar Jun 06 '19 07:06 fvermeulen

My understanding is this is now fixed. Can anyone verify reproduction of this issue?

JasonAHeron avatar Aug 09 '19 21:08 JasonAHeron