AppLovin / AppLovin-MAX-SDK-Android

Other
210 stars 95 forks source link

Why does the MaxInterstitialAd object require an activity parameter? #639

Closed omeratesss closed 1 month ago

omeratesss commented 3 months ago

Feature Description

I want to load Interstitial ads without opening an Activity. Therefore, the activity parameter is not needed. When I will show an Interstitial ad, the activity parameter is needed. Note: It requires an activity parameter for the MaxInterstitialAd object. But it is cast to context within Applovin SDK. You can see it below. Why does this situation exist? Why can't I give a context parameter to the MaxInterstitialAd object?

Ekran Resmi 2024-03-21 10 57 59

Ekran Resmi 2024-03-21 10 55 38

thomasmso commented 3 months ago

Hey @omeratesss - we actually had a few other inquiries with regards to these APIs. Last time we looked at it a few years ago, having an active Activity and passing that through to some mediated SDKs were a requirement. Things might have changed in 2024. We'll investigate next week and update this thread.

omeratesss commented 2 months ago

Hi @thomasmso , is there any progress? I am waiting for you.

thomasmso commented 2 months ago

@omeratesss - I looked into it, and the issue is there are many networks that require an Activity context to function. For example, if you want to integrate AdMob interstitial ads, it requires us to pass in an Activity context:

https://github.com/AppLovin/AppLovin-MAX-SDK-Android/blob/master/Google/src/main/java/com/applovin/mediation/adapters/GoogleMediationAdapter.java#L334

Would your integration have an Activity context by the time of display? One middleground solution I can think of is to allow for a non-Activity context for SDK init and ad load, but not on show.

omeratesss commented 2 months ago

@thomasmso, your proposed middleground solution aligns perfectly with our requirements. Our aim is to initialize the SDK and load ads using a non-activity context. When it comes to displaying the ad, we intend to utilize activity contexts.

thomasmso commented 2 months ago

@omeratesss - we're working on this - pushing new adapters to ensure if an Activity context is not needed, we won't look for one when loading. Then to update SDK to allow passing of the Activity context.

To prevent completely breaking current implementations, we'll likely just deprecate existing APIs first while adding the new ones.

thomasmso commented 1 month ago

@omeratesss - We just released Android SDK v12.5.0. Our MaxInterstitialAd class can be created without requiring an Activity context. Just make sure sure to pass in an Activity context when calling MaxInterstitialAd#show(...).