zngb zngb - 1 month ago 15
Android Question

AdMob loading multiple rewarded videos

I have multliple Ad Units setup in Admob, and each one is a rewarded video. My problem is I am rewarded different items depending on which video is watched, and I can only load one video

onCreate()
for example this loads only the video for AD_UNIT_3:

mAd.loadAd("AD_UNIT_1", new AdRequest.Builder().build());
mAd.loadAd("AD_UNIT_2", new AdRequest.Builder().build());
mAd.loadAd("AD_UNIT_3", new AdRequest.Builder().build());


How am I supposed to have a listener that rewards the item when
onRewarded()
is called, if I do not have control over which video (AD UNIT) to display from and thus have a listener for multiple units?

I have a solution setup now that loads the correct video from the correct ad unit by only loading it when I know that is the video that will be shown. For example, when they open up a "Coins" page I know they need the "Coins" video, and thus use the listener for "Coins" to reward the right item.

The big problem with this solution is the ad can take 10 seconds to load of course, and many users will hit that "Coins" page and try to load the ad within seconds - I have added my current code below that does not work.

I know I am thinking about this wrong because there is no one else with this problem :) I've been working on this for a long time and would appreciate any insight. Thank you!

onCreate()

mAd = MobileAds.getRewardedVideoAdInstance(this);

mAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewarded(RewardItem rewardItem) {
switch(Constants.currentAd) {
case("BUST"):
Log.d("AD","BUST: onRewarded()");
reverseBust();
Constants.currentAd = "";
break;

case("SKIPTRAVEL"):
Log.d("AD","SKIPTRAVEL: onRewarded()");
skipTravel();
Constants.currentAd = "";
break;

case("REMOVEHEAT"):
Log.d("AD","REMOVEHEAT: onRewarded()");
removeHeat();
Constants.currentAd = "";
break;

case("SKIPUPGRADEDEALER"):
Log.d("AD","SKIPUPGRADEDEALER: onRewarded()");
skipUpgradeDealer();
Constants.currentAd = "";
break;

case("SKIPDEALER"):
Log.d("AD","SKIPDEALER: onRewarded()");
//skipDealer();
Constants.currentAd = "";
break;
}

}
}`


Loading video

public void loadRewardedVideos(String name) {
switch(name) {
case("BUST"):
Constants.currentAd="BUST";
mAd.loadAd("AD_UNIT_ID_1", new AdRequest.Builder().build());
break;
case("SKIPTRAVEL"):
Constants.currentAd="SKIPTRAVEL";
mAd.loadAd("AD_UNIT_ID_2", new AdRequest.Builder().build());
break;
case("REMOVEHEAT"):
Constants.currentAd="REMOVEHEAT";
mAd.loadAd("AD_UNIT_ID_3", new AdRequest.Builder().build());
break;
case("SKIPUPGRADEDEALER"):
Constants.currentAd="SKIPUPGRADEDEALER";
mAd.loadAd("AD_UNIT_ID_4", new AdRequest.Builder().build());
break;
case("SKIPDEALER"):
Constants.currentAd="SKIPDEALER";
mAd.loadAd("AD_UNIT_ID_5", new AdRequest.Builder().build());
break;
}

}


Thank you!

Answer

You're thinking about this the wrong way. mAd is instanced, there can be only one. You need to handle the functionality and rewards using just one instance of mAd...