From 364b3fd3ba140ae6602d471645aa481323306469 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Sat, 5 Sep 2026 10:50:37 +0200 Subject: [PATCH] Replace the banner on a width change instead of resizing it AdView.setAdSize throws once the view has a size, and #643 made the view long-lived, so the first rotation that changed the banner width crashed the free app. Play's pre-launch report caught it on 4.19.0. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SG2XwLKA9P1wK629kp8cJq --- .../app/opendocument/droid/nonfree/AdManager.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/ads/java/app/opendocument/droid/nonfree/AdManager.kt b/app/src/ads/java/app/opendocument/droid/nonfree/AdManager.kt index d88afb9d3d16..59e0e1f058d9 100644 --- a/app/src/ads/java/app/opendocument/droid/nonfree/AdManager.kt +++ b/app/src/ads/java/app/opendocument/droid/nonfree/AdManager.kt @@ -317,15 +317,24 @@ class AdManager { return } - val adView = this.adView ?: addAdView().also { this.adView = it } - // an anchored banner keeps the size it was asked at, so a real width change needs a new // one - but a keyboard opening, or a rotation back, does not - if (adWidth == requestedWidth) { + val previous = this.adView + if (previous != null && adWidth == requestedWidth) { return } requestedWidth = adWidth + // AdView.setAdSize throws once the view has a size, so a width change replaces the banner + // rather than resizing it, and the ad that was up goes with it + if (previous != null) { + destroyAdView() + adContainer.removeView(previous) + hasAd = false + } + + val adView = addAdView().also { this.adView = it } + adView.setAdSize(adSize) retries.removeCallbacksAndMessages(null)