我尝试在mainactivity中加载横幅广告并向其显示所有其他活动,因此广告被加载并很好地显示在mainactivity中,但是当我尝试在其他活动中对其进行展示时,我的代码中出现了此问题:W /广告:#004网络视图被破坏。忽略动作。
MainActivity.java
public void showPersonalizedAds() {
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
mAdView.setVisibility(View.VISIBLE);
}
@Override
public void onAdFailedToLoad(int error)
{
mAdView.setVisibility(View.GONE);
}
});
}
DownloadActivity.java
MainActivity.app.showPersonalizedAds();
mainacvitiy.xml
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:visibility="gone"
android:layout_alignParentBottom="true"
ads:adUnitId="@string/banner_ad_unit_id">
downloadactivity.xml
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
android:visibility="gone"
android:layout_alignParentBottom="true"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</com.google.android.gms.ads.AdView>