【问题标题】:Android AdMob completely remove a InterstitialAd objectAndroid AdMob 完全移除一个 InterstitialAd 对象
【发布时间】:2013-05-07 15:48:28
【问题描述】:

我正在为我的项目制作广告,我注意到广告占用了大量内存。我想我只需要忍受它。但我不想忍受的是,我似乎无法找到完全删除广告对象以恢复记忆的方法。

我正在使用 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 对象并取回内存?

【问题讨论】:

    标签: java android memory-leaks admob


    【解决方案1】:

    一旦您的 onDismissScreen() 方法被调用,您就不再有对插页式广告的引用,因此垃圾收集器应该能够随时取回该内存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多