我正在使用这种依赖:
compile 'com.google.firebase:firebase-ads:10.0.0'
添加横幅广告后,我的活动开始泄漏,但泄漏事件给了我有趣的分析,我无从谈论:
这就是我将广告添加到我的MainActivity中的方式:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
initializeAds();
}
private void initializeAds() {
MobileAds.initialize(getApplicationContext(), getString(R.string.ad_app_id));
AdRequest adRequest = new AdRequest.Builder()
.build();
adView.loadAd(adRequest);
}
/** Called when leaving the activity */
@Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}
/** Called when returning to the activity */
@Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}
@Override
protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
添加AdView后,它开始泄漏给我。什么在这里保持对我的活动的参考?你有什么想法吗?