0

私はインタースティシャル広告を呼び出すためにshowAd()内部OnResumeで呼び出しています。

ShowAd()

public void showAd()   
{   
    SavedFrequency = getSharedPreferences("adfreq", MODE_PRIVATE);
    AdfrequencyInt = SavedFrequency.getInt("adfreq", 0);
    AdfrequencyInt++;
    if (AdfrequencyInt > 59) 
    {
        AdfrequencyInt = 0;
    }
    Toast.makeText(this, ""+AdfrequencyInt, Toast.LENGTH_SHORT).show(); 
    SharedPreferences.Editor preferencesEditorF1 = SavedFrequency.edit();
    preferencesEditorF1.putInt("adfreq", AdfrequencyInt);
    preferencesEditorF1.apply();

    if (AdfrequencyInt % 10 == 0) 
    {
        interstitialAd = new InterstitialAd(this, MY_PUBLISHER_ID); // Create an ad
        interstitialAd.setAdListener(this); // Set the AdListener.
        AdRequest adRequest = new AdRequest();
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        interstitialAd.loadAd(adRequest);
    }
}   

質問:

広告を表示することはできますが、通常は遅れます。つまり、別のアクティビティを既に開始しているときに、まだバックグラウンドで読み込み中で、突然広告が飛び出します。このアクティビティに戻ったときにのみ広告が表示されるように、広告を最初にロードしてバックグラウンドで保存するにはどうすればよいですか?

ありがとう!

4

2 に答える 2

0

Google Developer サイトにあるように、この方法で改善する必要があります: http://developer.android.com/reference/com/google/android/gms/ads/InterstitialAd.html

     mNextLevelButton.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {
             // Show the interstitial if it is ready. Otherwise, proceed to the next level
             // without ever showing it.
             if (mInterstitialAd.isLoaded()) {
                 mInterstitialAd.show();
             } else {
                 // Proceed to the next level.
                 goToNextLevel();
             }
         }

正常にロードされた場合は表示し、そうでない場合は直接別のアクティビティに移動します。

于 2014-01-26T10:57:41.750 に答える