Rewarded Videos doesn't load the first time but loads after

Viewed 1591

My App has a button to open reward videos >> when this button is pressed for the first time, it toasts "Check your Internet connection", when hit the second or third time, it shows the video with no problems

    MobileAds.initialize(getActivity(), getString(R.string.VID_App_ID));
    mRewardVideoAd = MobileAds.getRewardedVideoAdInstance(getActivity());
    mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
            .addTestDevice(getString(R.string.TestDeviceID))
            .build());
    mRewardVideoAd.setRewardedVideoAdListener(this);
    loadRewardedVideoAd();   

Here are the methods used :

 private void loadRewardedVideoAd() {
        mRewardVideoAd.loadAd(getString(R.string.VID_App_Unit_ID), new AdRequest.Builder()
                .addTestDevice(getString(R.string.TestDeviceID))
                .build());
    }



   @OnClick(R.id.button_more_money)
    public void more_money() {
        if (mRewardVideoAd.isLoaded()) {
            mRewardVideoAd.show();
        } else
            { 
             Toast.makeText(getActivity(), "Check your internet connection", Toast.LENGTH_LONG).show();
            loadRewardedVideoAd();
               }

    }


    @Override
    public void onResume() {
        mRewardVideoAd.resume(getActivity());
        super.onResume();
        loadRewardedVideoAd();
    }

Edit: Solved - It took some time and the solution was to load at onCreate() Thanks to Martin De Simone and Avi Levin

2 Answers
Related