2013-05-07 80 views
0

Iam負責我項目的廣告,並且我注意到廣告需要相當多的內存。我想我必須忍受這一點。但我不想與之共處的是,我似乎無法找到一種方法來徹底刪除廣告對象,以恢復記憶。Android AdMob完全刪除InterstitialAd對象

我現在用的是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對象並獲取內存回來?

回答

0

一旦您的onDismissScreen()方法被調用,您就再也沒有對插頁式廣告的引用,所以垃圾收集器應該能夠隨時取回內存。