Repository navigation
v1.3.2
AdManageKit Release Notes
Version 1.3.2
Release Date: May 22, 2025
Overview
This release enhances the ad management system in the com.i2hammad.admanagekit.admob package, introducing per-ad-unit caching, a 1-hour ad expiration mechanism, and a new boolean parameter to control whether cached or new ads are served. These changes improve ad delivery performance, reduce network requests, and ensure robust ad handling across NativeBannerSmall, NativeBannerMedium, and NativeLarge ad formats.
New Features
- Per-Ad-Unit Caching:
- Ads are now cached per
adUnitId, allowing multiple ad units to maintain separate cached ads. - Implemented in
NativeAdManagerusing aMutableMap<String, CachedAd>to store ads with their timestamps.
- Ads are now cached per
- 1-Hour Ad Expiration:
- Cached ads expire after 1 hour (3600 seconds) to ensure freshness.
- Expired ads are automatically destroyed and removed from the cache to prevent memory leaks.
- Boolean Option for Cached/New Ads:
- Added
useCachedAd: Booleanparameter (default:false) toloadNativeBannerAd(NativeBannerSmall,NativeBannerMedium) andloadNativeAds(NativeLarge). - When
useCachedAdistrue, a valid cached ad (not expired) is served if available; otherwise, a new ad is fetched.
- Added
- Fallback to Cached Ads:
- If a new ad fails to load and
useCachedAdisfalse, the system attempts to serve a valid cached ad for the sameadUnitIdbefore triggering a failure callback.
- If a new ad fails to load and
Enhancements
- Unified Caching Logic:
- Replaced
enableCachingLargeNativeAdsinNativeLargewithenableCachingNativeAdsinNativeAdManagerfor consistent caching control across all ad formats. - Standardized caching methods (
setCachedNativeAd(adUnitId, nativeAd),getCachedNativeAd(adUnitId)) across all ad classes.
- Replaced
- Improved AdChoices Handling:
- Enhanced
adChoicesViewlogic inNativeBannerMediumandNativeLargeto checknativeAd.adChoicesInfodirectly, ensuring proper visibility and avoiding redundant assignments.
- Enhanced
- Consistent Logging and Visibility:
- Added detailed logging for ad loading, failures, and caching events (e.g., "No valid cached ad available for adUnitId").
- Standardized visibility constants (
View.GONE,View.VISIBLE,View.INVISIBLE) across all classes.
- Memory Management:
NativeAdManagerdestroys old or expired ads when caching new ones or clearing the cache, preventing memory leaks.- Added
clearCachedAd(adUnitId)andclearAllCachedAds()methods to manage ad lifecycle.
Bug Fixes
- Fixed inconsistent
adChoicesViewhandling inNativeBannerMediumby simplifying visibility logic. - Corrected
firebaseAnalyticsinitialization to ensure it’s set before use indisplayAdmethods. - Removed redundant
NativeAdManagermethods (e.g.,setCachedNativeLargeAd,getCachedNativeLargeAd) to streamline caching logic.
Breaking Changes
NativeAdManagermethodssetCachedNativeAdandgetCachedNativeAdnow require anadUnitIdparameter to support per-ad-unit caching.- Removed
enableCachingLargeNativeAdsfromNativeLarge; useNativeAdManager.enableCachingNativeAdsinstead. - Apps using the old single-ad caching methods must update to the new per-ad-unit caching approach.
Usage Example
// Load a new ad
val nativeBannerSmall = NativeBannerSmall(context)
nativeBannerSmall.loadNativeBannerAd(activity, "your-ad-unit-id", useCachedAd = false, object : AdLoadCallback {
override fun onAdLoaded() { Log.d("Ad", "Ad loaded") }
override fun onFailedToLoad(adError: LoadAdError) { Log.d("Ad", "Ad failed: ${adError.message}") }
override fun onAdImpression() { Log.d("Ad", "Ad impression") }
override fun onAdClicked() { Log.d("Ad", "Ad clicked") }
override fun onAdClosed() { Log.d("Ad", "Ad closed") }
})
// Load a cached ad if available and not expired
nativeBannerSmall.loadNativeBannerAd(activity, "your-ad-unit-id", useCachedAd = true)Recommendations
- Thread Safety: If multiple ad units are loaded concurrently, consider making
NativeAdManager.cachedAdsthread-safe usingCollections.synchronizedMaporConcurrentHashMap. - Testing: Verify caching behavior with:
- Multiple ad units to ensure per-ad-unit caching.
- Ads just before/after the 1-hour expiration.
- Toggling
useCachedAdandenableCachingNativeAds.
- Lifecycle Management: Call
NativeAdManager.clearAllCachedAds()in appropriate lifecycle methods (e.g.,onDestroy) to free resources.
Known Limitations
- Ad expiration is managed manually (1 hour) as Google’s
NativeAddoes not provide built-in expiration metadata. Verify with your ad provider (e.g., AdMob) for specific policies. - No automatic cache refresh; apps must explicitly request new ads when needed.
Dependencies
- No new dependencies introduced.
- Requires existing dependencies: Google AdMob SDK, Firebase Analytics, Shimmer, and project-specific resources (
R.layout,BillingConfig,AdManager).
Acknowledgments
These changes improve ad performance and reliability, ensuring a seamless user experience while maintaining compliance with ad provider policies.
Full Changelog: v1.3.1...v1.3.2