I am trying to set the function to switch to a new activity when watching a rewarded ad. The function is realized through the use of a picture. My code works like this. When he clicks on the picture, he shows an ad with a reward, and if the user has not watched the ad and closed the ad, he will still get to the new activity if he did not watch the ad. What's wrong with my code?)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selection);
Log.d(LOG_TAG, "SAonCreate");
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) { }
});
mRewardedVideoAd= MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",new AdRequest.Builder().build()); // You need to pass your rewared video ad Id here...
mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() {
@Override
public void onRewardedVideoAdLoaded() {
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",new AdRequest.Builder().build());
onRewardedVideoAdClosed();
}
@Override
public void onRewarded(RewardItem rewardItem) {
adHasBeenSeen = 1;
Toast.makeText(SelectionActivity.this, R.string.congratulations, Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdLeftApplication() {
//User clicked on ad here write your caching code here....
Toast.makeText(SelectionActivity.this, "Clicked on Ad", Toast.LENGTH_SHORT).show();
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
@Override
public void onRewardedVideoCompleted() {
}
});
findViewById(R.id.rad_button6).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mRewardedVideoAd.isLoaded()) {
ImageView imageView = (ImageView) view;
Intent intent = new Intent(SelectionActivity.this, TutorialActivity.class);
intent.putExtra("i", Integer.parseInt(imageView.getTag().toString()));
startActivity(intent);
mRewardedVideoAd.show();
findViewById(R.id.rad_button6).setVisibility(View.GONE);
}
else {
Toast.makeText(SelectionActivity.this, R.string.please_wait, Toast.LENGTH_SHORT).show();
}
}
});
findViewById(R.id.rad_button10).setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (mRewardedVideoAd.isLoaded()) {
ImageView imageView = (ImageView) view;
Intent intent = new Intent(SelectionActivity.this, TutorialActivity.class);
intent.putExtra("i", Integer.parseInt(imageView.getTag().toString()));
startActivity(intent);
mRewardedVideoAd.show();
findViewById(R.id.rad_button10).setVisibility(View.GONE);
}
else {
Toast.makeText(SelectionActivity.this, R.string.please_wait, Toast.LENGTH_SHORT).show();
}
}
});
The answer is - put booalen at the code.