prebid-mobile-android icon indicating copy to clipboard operation
prebid-mobile-android copied to clipboard

java.lang.RuntimeException: Can't create handler inside thread during BannerAdUnit creation

Open sarbyn opened this issue 9 months ago • 1 comments

Describe the bug In or project, the Bid requests are done in a Dispatchers.IO coroutine scope.

So, in this scope, we build InterstitialAdUnit or BannerAdUnit instance, and then call the fetchDemand method in order to call the backend with the new adUnit. It works fine until version 2.5.0: now it is impossible to start the requuest, because the BannerAdUnit requires a timer, and does not work in our coroutine scopes.

java.lang.RuntimeException: Can't create handler inside thread Thread[DefaultDispatcher-worker-9,5,main] that has not called Looper.prepare()
	at android.os.Handler.<init>(Handler.java:228)
	at android.os.Handler.<init>(Handler.java:130)
	at android.os.CountDownTimer$1.<init>(CountDownTimer.java:129)
	at android.os.CountDownTimer.<init>(CountDownTimer.java:129)
	at org.prebid.mobile.VisibilityMonitor$VisibilityTimer.<init>(VisibilityMonitor.java:74)
	at org.prebid.mobile.VisibilityMonitor.<init>(VisibilityMonitor.java:26)
	at org.prebid.mobile.AdUnit.<init>(AdUnit.java:74)
	at org.prebid.mobile.AdUnit.<init>(AdUnit.java:86)
	at org.prebid.mobile.BannerBaseAdUnit.<init>(BannerBaseAdUnit.java:33)
	at org.prebid.mobile.BannerAdUnit.<init>(BannerAdUnit.java:43)
	at xxx.xxxx.xxxxx.xxxxx.PrebidHelper.getPrebidAdUnits$library_debug(PrebidHelper.kt:54)

It seems related to https://github.com/prebid/prebid-mobile-android/pull/804

To Reproduce Steps to reproduce the behavior:

  1. Create an instance of BannerAdUnit in a Dispatchers.IO coroutine scope

Expected behavior It is possible to create an instance of BannerAdUnit

Smartphone (please complete the following information):

  • Device: Any Android
  • Version : only on 2.5.0

sarbyn avatar Apr 08 '25 08:04 sarbyn

It happens also on Prebid 3.0.0

sarbyn avatar Apr 14 '25 16:04 sarbyn

Issue has been fixed in 3.0.1

mdanylov-sigma avatar May 12 '25 16:05 mdanylov-sigma