• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Load multiple Ad Video Reward in one Activity

Emma_bk

Lurker
I've set the reward of my Video Ad to be the access to another activity, but my issue is that I have multiple button on the MainActivity and I want the Reward (to switch to another Activity) to be different for each button.

Ex :

Btn1 --> Video --> lead to Activity1
Btn2 --> Video --> lead to Activity2
Btn3 --> Video --> lead to Activity3, and so on.​

Here is my code :

Code:
mAd = MobileAds.getRewardedVideoAdInstance(this);
   mAd.setRewardedVideoAdListener(this);
   loadRewardedVideo();

private void loadRewardedVideo(){
   if(!mAd.isLoaded()){
       mAd.loadAd("ca-app-pub-1219738656561849/8210125961", new AdRequest.Builder().build());
   }
}
@Override
public void onRewardedVideoAdLoaded() {
}

@Override
public void onRewardedVideoAdOpened() {

}

@Override
public void onRewardedVideoStarted() {

}

@Override
public void onRewardedVideoAdClosed() {
   loadRewardedVideo();
}

@Override
public void onRewarded(RewardItem rewardItem) {
   flag=true;
   startActivity(new Intent(MainActivity.this, Activity1.class));
}

@Override
public void onRewardedVideoAdLeftApplication() {

}

@Override
public void onRewardedVideoAdFailedToLoad(int i) {

}

@Override
public void onRewardedVideoCompleted() {

}

 //This is the onClick of the button 1
public void Btn1(View view) {
   vibrator.vibrate(50);
   if(mAd.isLoaded()){
       mAd.show();
   }
}

 //This is the onClick of the button 2
public void Btn2(View view) {
      //I want this button to lead to Activity2.class but how?
   }
}

@Override
protected void onPause() {
   mAd.pause(this);
   super.onPause();
}

@Override
protected void onResume() {
   mAd.resume(this);
   super.onResume();
}

I was thinking of someting like this :

Code:
Button Button1 = findViewById(R.id.Btn1);
       Button1.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               if(flag==true){
                   startActivity(new Intent(MainActivity.this, Activity1.class));
               }else {
                   Toast.makeText(MainActivity.this, "Plaese watch Video First", Toast.LENGTH_SHORT).show();
               }
           }
       });

But when I click on the button it only show the Toast and don't load the video. Any help or advice is more than welcome ! Thanks in advance
 
So the only place where flag is set to True, is method onRewarded(). I'm guessing that this method is never called.
 
Back
Top Bottom