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

Admob Reward Video between activities

Emma_bk

Lurker
Hello ! I've set the reward of my Video Ad to be the access to another activity, but the ads don't load anymore (I've had the code for a week and it was fine until today).

My second issues 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 lead to Activity1, Btn2 lead to Activity 2, 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());
        }
    }
    [USER=1021285]@override[/USER]
    public void onRewardedVideoAdLoaded() {
    }

    [USER=1021285]@override[/USER]
    public void onRewardedVideoAdOpened() {

    }

    [USER=1021285]@override[/USER]
    public void onRewardedVideoStarted() {

    }

    [USER=1021285]@override[/USER]
    public void onRewardedVideoAdClosed() {
        loadRewardedVideo();
    }

    [USER=1021285]@override[/USER]
    public void onRewarded(RewardItem rewardItem) {
        flag=true;
        startActivity(new Intent(MainActivity.this, Activity1.class));
    }

    [USER=1021285]@override[/USER]
    public void onRewardedVideoAdLeftApplication() {

    }

    [USER=1021285]@override[/USER]
    public void onRewardedVideoAdFailedToLoad(int i) {

    }

    [USER=1021285]@override[/USER]
    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?
        }
    }

    [USER=1021285]@override[/USER]
    protected void onPause() {
        mAd.pause(this);
        super.onPause();
    }

    [USER=1021285]@override[/USER]
    protected void onResume() {
        mAd.resume(this);
        super.onResume();
    }

As for the problem of different button and the same reward (watching an ad to switch to an activity) I was thinking of someting like this :


Code:
Button Button1 = findViewById(R.id.Btn1);
            Button1.setOnClickListener(new View.OnClickListener() {
                [USER=1021285]@override[/USER]
                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 buttun it only show the Toast, what's the problem here?

Any help or advice is more than welcome ! Thanks in advance
 
Last edited:
Thanks for replying @dontpanicbobby !

No, the reward is accessing an activity. The MainActivity have 4 buttons, so when the user click on a button it should go like :
Btn1 --> watch the video until the end --> access Activity1.class
Btn2 --> watch the video until the end --> access Activity2.class
Btn3 --> watch the video until the end --> access Activity3.class, ...

But I don't get how or where to assign that. I have tried to make the code in the onClick of the buttons but the video won't load.
 
Back
Top Bottom