簡體   English   中英

Android AdMob會完全刪除InterstitialAd對象

[英]Android AdMob completely remove a InterstitialAd object

Iam正在為我的項目制作廣告,我注意到這些廣告占用了大量內存。 我想我只需要忍受這一點。 但我不想忍受的是,我似乎找不到完全刪除廣告對象以恢復記憶的方法。

我正在使用InterstialAds,這是我的主要活動:

public class Main extends Activity implements Constants, AdListener
{
    private GameView mGameView;
    private Activity mThis = this;
    private AdListener mThisListener = this;
    private InterstitialAd mFullScreenAd;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        mGameView = new GameView(this, getAssets()); 
        setContentView(mGameView);
    }

    public void showAd()
    {
        mFullScreenAd = new InterstitialAd(mThis, "asdasdasdasd");

        // Create ad request
        AdRequest adRequest = new AdRequest();

        // Begin loading your interstitial
        mFullScreenAd.loadAd(adRequest);

        // Set Ad Listener to use the callbacks below
        mFullScreenAd.setAdListener(mThisListener); 
    }

    public void onDismissScreen(Ad ad) 
    {
        mFullScreenAd.stopLoading();
        mFullScreenAd = null;
    }

    public void onFailedToReceiveAd(Ad ad, ErrorCode errorCode) {

    }

    public void onLeaveApplication(Ad ad) {

    }

    public void onPresentScreen(Ad ad) {

    }

    public void onReceiveAd(Ad ad) 
    {    
        if (ad == mFullScreenAd) 
            mFullScreenAd.show();
    }
}

所以我的問題是:如何完全刪除mFullScreenAd對象並找回內存?

一旦調用了onDismissScreen()方法,您就不再需要對插頁式廣告的引用,因此垃圾收集器應該能夠在需要時取回該內存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM