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 :
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 :
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
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: