we are currently building an application which includes rewarded video system by AdMob. Application has one MainActivity and there are fragments that are constructed on it. Each fragment has a button, each fragment implements "RewardedVideoAdListener". When the buttons are clicked, rewarded videos are loaded and shown. Now the thing is, each button should have different type of rewards.
The both fragments look like this;
public class FragmentShop extends Fragment implements RewardedVideoAdListener
{
private RewardedVideoAd rewardedVideoAd;
private Button rewardButton;
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rewardButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(rewardedVideoAd.isLoaded()){
rewardedVideoAd.show();
rewardButton.setVisibility(View.INVISIBLE);
}
else {
Toast.makeText(view.getContext(),"Try again!",Toast.LENGTH_SHORT).show();
loadRewardedVideoAd();
}
}
});
}
private void loadRewardedVideoAd() {
rewardedVideoAd.loadAd("---", //there is our key
new AdRequest.Builder().build());
}
@Override
public void onRewarded(RewardItem rewardItem) {
//Some database actions.
loadRewardedVideoAd();
}
}
The problem is, no matter which button we click, only the onRewarded() function runs which is in the fragment no 2. So how we can build a structure where each fragment runs their own onRewarded() function. Should we use onRewardedVideoCompleted() at first?