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)
@MeghaB can you take a look pls?
/assign @MeghaB
cc @JasonAHeron ... I knew the day would come when we'd have to reckon with FiamWindowManager
yup, thanks @vkryachko!
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.
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?
@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
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
plz solve the crash :(
I'm also facing the issue, I'm wondering if there's a way to catch the error at least.
i guess it happens because of splash activity close while Dialog is opening
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?
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.
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)
@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?
plz solve the crash :(
4 months.... i think we will soon be celebrating happy aniversary to this issue
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?
Any news regarding this crash?
Is there any progress?
My understanding is this is now fixed. Can anyone verify reproduction of this issue?
@JasonAHeron , this is NOT fixed... and as far as i know google is putting ZERO EFFORTS in solving it because this is a fee free google tool... so they dont get any money from us for doing it they dont give a shit about supporting us in counterpart
you can use FCM to create a tool for doing the same thing in-app messaging does... I did
Have you tested the most current version of the SDK?
https://firebase.google.com/support/release-notes/android#version_1802
Hey @wtopolski. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@wtopolski if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
I am using:
implementation 'com.google.firebase:firebase-inappmessaging-display:18.0.2'
And I also having this issue with some users. It is obviously Picasso that is causing this problem. Please fix it.
Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView + 891(ViewRootImpl.java:891)
at android.view.WindowManagerGlobal.addView + 372(WindowManagerGlobal.java:372)
at android.view.WindowManagerImpl.addView + 128(WindowManagerImpl.java:128)
at com.google.firebase.inappmessaging.display.internal.FiamWindowManager.show + 62(FiamWindowManager.java:62)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$5$4.run + 433(FirebaseInAppMessagingDisplay.java:433)
at android.app.Activity.runOnUiThread + 6551(Activity.java:6551)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$5.onSuccess + 429(FirebaseInAppMessagingDisplay.java:429)
at com.squareup.picasso.RequestCreator.into + 721(RequestCreator.java:721)
at com.google.firebase.inappmessaging.display.internal.FiamImageLoader$FiamImageRequestCreator.into + 65(FiamImageLoader.java:65)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.loadNullableImage + 511(FirebaseInAppMessagingDisplay.java:511)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.inflateBinding + 367(FirebaseInAppMessagingDisplay.java:367)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay.access$400 + 83(FirebaseInAppMessagingDisplay.java:83)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$2.run + 303(FirebaseInAppMessagingDisplay.java:303)
at android.os.Handler.handleCallback + 808(Handler.java:808)
at android.os.Handler.dispatchMessage + 101(Handler.java:101)
at android.os.Looper.loop + 166(Looper.java:166)
at android.app.ActivityThread.main + 7529(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run + 245(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main + 921(ZygoteInit.java:921)
from Crashlytics
ImageViewAction.java line 51
com.squareup.picasso.ImageViewAction.complete
This crash is usually caused by your app trying to display a dialog using a previously-finished Activity as a context. For example, this can happen if an Activity triggers an AsyncTask that tries to display a dialog when it is finished, but the user navigates back from the Activity before the task is completed.
here is a case ...
1 app start
2 splashscreen activity opens
3 Inapp dialog pops up
4 splashscreen activity close
5 inapp dialog crash
Got few hits as well
implementation 'com.google.firebase:firebase-inappmessaging-display:19.0.0'
I am still having it.
I noticed that you have closed this issue? Should we open a new one?
Fatal Exception: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView + 890(ViewRootImpl.java:890)
at android.view.WindowManagerGlobal.addView + 342(WindowManagerGlobal.java:342)
at android.view.WindowManagerImpl.addView + 97(WindowManagerImpl.java:97)
at com.google.firebase.inappmessaging.display.internal.FiamWindowManager.show + 62(FiamWindowManager.java:62)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$5$4.run + 434(FirebaseInAppMessagingDisplay.java:434)
at android.app.Activity.runOnUiThread + 6030(Activity.java:6030)
at com.google.firebase.inappmessaging.display.FirebaseInAppMessagingDisplay$5.onSuccess + 430(FirebaseInAppMessagingDisplay.java:430)
at com.squareup.picasso.ImageViewAction.complete + 52(ImageViewAction.java:52)
at com.squareup.picasso.Picasso.deliverAction + 576(Picasso.java:576)
at com.squareup.picasso.Picasso.complete + 528(Picasso.java:528)
at com.squareup.picasso.Picasso$1.handleMessage + 122(Picasso.java:122)
at android.os.Handler.dispatchMessage + 102(Handler.java:102)
at android.os.Looper.loop + 154(Looper.java:154)
at android.app.ActivityThread.main + 6646(ActivityThread.java:6646)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 1468(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main + 1358(ZygoteInit.java:1358)
There is one work-around for this issue: use custom event to trigger in-app message not on Splash screen, but rather on the main screen.
Current problem occurs because in-app message is trying to display itself in the scope of Splash screen activity, that, probably, disappears faster, than message is shown.
Not sure, how they will be able to fix this issue, other than my proposition. The only thing they can add is null check for Activity to remove crashes.
There is one work-around for this issue: use custom event to trigger in-app message not on Splash screen, but rather on the main screen.
Current problem occurs because in-app message is trying to display itself in the scope of Splash screen activity, that, probably, disappears faster, than message is shown.
Not sure, how they will be able to fix this issue, other than my proposition. The only thing they can add is null check for Activity to remove crashes.
Currently, the crashes I am getting are tied to default "on_foreground" event. Maybe if I set campaigns to "screen_view", it won't crash...
There is one work-around for this issue: use custom event to trigger in-app message not on Splash screen, but rather on the main screen.
Current problem occurs because in-app message is trying to display itself in the scope of Splash screen activity, that, probably, disappears faster, than message is shown.
Not sure, how they will be able to fix this issue, other than my proposition. The only thing they can add is null check for Activity to remove crashes.Currently, the crashes I am getting are tied to default "on_foreground" event. Maybe if I set campaigns to "screen_view", it won't crash...
That's right, because "on_foreground" event is default one, that is sent to Firebase when app starts.
I tried it with "screen_view" and it is still crashing. It seems like as the image related component (picasso) gets loaded and shown whenever it wants, this cannot be fixed by ourselves unless we implement our own In-App Messaging-Display class and use a different image library or use picasso more carefully. As Google is not going to fix this. The only solutions are either not to use image based in-app messages or not to use Google's In-App Messaging-Display class. I think Google is testing this only where they are located (500mbit+ bandwidth) where images are loaded instantly, etc..
@vkryachko @samtstern @MeghaB @JasonAHeron please re-open this issue, it's not fixed & still occurring.
@vkryachko @samtstern @MeghaB @JasonAHeron please re-open this issue, it's not fixed & still occurring.
I do not think they care about this and that is why I will stop using Firebase In-App Messaging and I will make my own one. It is sad: I was supposed to save time using Firebase features :|
Most helpful comment
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?