2017-03-08 82 views
0

我的应用程序在应用程序中显示插页式广告,有时在应用程序因Internet速度较慢而关闭后显示。在应用关闭后展示插页式广告违反了admob规则。如何阻止我的插页式广告在应用关闭后显示广告?如何停止应用退出后显示的插页式广告?

public class des extends AppCompatActivity { 
 

 
    ImageButton imageView15; 
 
    InterstitialAd mInterstitialAd; 
 
    private InterstitialAd interstitial; 
 

 
    @Override 
 
    protected void onCreate(Bundle savedInstanceState) { 
 
     super.onCreate(savedInstanceState); 
 
     setContentView(R.layout.activity_des); 
 

 
     AdView mAdView = (AdView) findViewById(R.id.AdView); 
 
     AdRequest adRequest = new AdRequest.Builder().build(); 
 
     mAdView.loadAd(adRequest); 
 

 
        // Prepare the Interstitial Ad 
 
     interstitial = new InterstitialAd(des.this); 
 
// Insert the Ad Unit ID 
 
     interstitial.setAdUnitId(getString(R.string.intertitial_id)); 
 

 
     interstitial.loadAd(adRequest); 
 
// Prepare an Interstitial Ad Listener 
 
     interstitial.setAdListener(new AdListener() { 
 
      public void onAdLoaded() { 
 
       // Call displayInterstitial() function 
 
       displayInterstitial(); 
 
      } 
 
     }); 
 

 

 
     imageView15 = (ImageButton) findViewById(R.id.imageView15); 
 
     imageView15.setOnClickListener(new View.OnClickListener() { 
 
      @Override 
 
      public void onClick(View v) { 
 
       Intent intentLoadNewActivity = new Intent(des.this,vid.class); 
 
       startActivity(intentLoadNewActivity); 
 
      } 
 
     }); 
 

 

 
    } 
 

 
    public void displayInterstitial() { 
 
// If Ads are loaded, show Interstitial else show nothing. 
 
     if (interstitial.isLoaded()) { 
 
      interstitial.show(); 
 
     } 
 
    } 
 

 

 
}

回答

1

你需要销毁活动结束或(退出应用程序)广告

试试这个

@Override 
public void onDestroy() 
{ 
    super.onDestroy(); 
    if (mInterstitialAd != null) { 
     mInterstitialAd.destroy(); 
    } 
} 
+0

您可以编辑我的Java代码与任何的onDestroy服务类(),因为当我尝试它不是工作摧毁字变成红色,我不知道如何修复它我trired ALT +进入即时通讯新的应用程序开发 –

+0

您需要重写onDestroy()方法快捷键(Ctrl + O) –

+0

尝试运行没有如果块只是销毁方法 –

2

的问题是,你是显示的加入OnAdLoaded,这是不建议的。当用户正在做其他工作时,这会导致不良行为和拦截。您应该在交流时加载您的广告tivity开始,然后你应该在没有检查用户是否被加载的情况下显示它。 这样你的广告就不会在用户完成你的应用程序后显示,你的问题将得到解决。

0

您可以跟踪活动的生命周期,然后在展示广告之前检查活动是否正在运行。

  1. 创建一个实例变量:

    private boolean isRunning; 
    
  2. 跟踪活动的生命周期:

    public void displayInterstitial() { 
        // If Ads are loaded and the activity is running, show Interstitial else show nothing. 
        if (isRunning && interstitial.isLoaded()) { 
         interstitial.show(); 
        } 
    } 
    

    @Override 
    protected void onStart() { 
        super.onStart(); 
        isRunning = true; 
    } 
    
    @Override 
    protected void onStop() { 
        super.onStop(); 
        isRunning = false; 
    } 
    
  3. 检查活动是展示广告前运行

+0

它工作!多谢 –

0

或者,你可以使用:system.exit(0);每当用户希望只要退出你的应用程序为您的应用程序不包含

相关问题