我已经阅读了几篇关于在隐藏/最小化应用程序时尝试停止 adView 的文章,但这会使我的应用程序崩溃。
这是我的代码,adView.LoadAd... 和 adView.stopLoading 都在启动时使应用程序崩溃。
public class MainActivity extends Activity implements OnItemSelectedListener {
@Override
protected void onResume() {
super.onResume();
if (AdViewStarted = true) {
adView.loadAd(new AdRequest());
}
}
@Override
protected void onPause() {
super.onPause();
if (AdViewStarted = true) {
adView.destroy();
}
}
[...]
public class AdMob extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adView = new AdView(this, AdSize.BANNER,"12345678901234567890");
LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
layout.addView(adView);
adView.loadAd(new AdRequest());
AdViewStarted = true;
}
@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
}
提前致谢