当我尝试通过插页式广告中的关闭按钮关闭广告时,该特定广告即被关闭。但随后又加载了一个广告。应用程序将以这种方式永远持续下去。
如何避免在手动关闭其他广告后加载它?
这是我的代码:
SET @paymentId := 1, @token := 'XF-BankResponseNo', @payerID := 234, @drawID := 1;
SELECT TotalTickets into @MaxTicketNo FROM Draw WHERE ID = @DrawID;
WITH RECURSIVE TicketNumbers (n) AS
(
SELECT 1
UNION ALL
SELECT n + 1 FROM TicketNumbers WHERE n < @MaxTicketNo
)
INSERT INTO transaction (PaymentID, TokenID, PayerID, DrawID, TicketNo)
SELECT @paymentId, @token, @PayerID, @DrawID, n
FROM TicketNumbers
ORDER BY Rand() LIMIT 1;
和displayInterstitial()方法是
static View setupListView(final Activity activity, View convertView, final ViewGroup parent,
MediaBrowserCompat.MediaItem item) {
if (sColorStateNotPlaying == null || sColorStatePlaying == null)
initializeColorStateLists(activity);
MediaDescriptionCompat description = item.getDescription();
final MediaItemViewHolder holder;
Integer cachedState = STATE_INVALID;
holder = new MediaItemViewHolder();
if (MediaIDHelper.ADVERTISEMENT.equals(description.getMediaId())) {
// Advert show
convertView = LayoutInflater.
from(activity).
inflate(R.layout.fragment_list_ad, parent, false);
try {
MobileAds.initialize(activity, activity.getString(R.string.admob_app_id));
holder.mAdView = convertView.findViewById(R.id.itemAd);
adRequest = new AdRequest.Builder().build();
holder.mAdView.loadAd(adRequest);
} catch (Exception ex) {
Log.e(TAG, ex.getMessage());
}
return convertView;
}
else if (MediaIDHelper.isItemHeader(description.getMediaId())) {
convertView = LayoutInflater.
from(activity).
inflate(R.layout.fragment_list_header, parent, false);
}
else if (MediaIDHelper.isEBookHeader(description.getMediaId())) {
convertView = LayoutInflater.
from(activity).
inflate(R.layout.fragment_ebook_header, parent, false);
MobileAds.initialize(activity, activity.getString(R.string.admob_app_id));
AdRequest adIRequest = new AdRequest.Builder().build();
holder.interstitial = new InterstitialAd(activity);
holder.interstitial.setAdUnitId(activity.getString(R.string.admob_interstitial_id));
// Interstitial Ad load Request
holder.interstitial.loadAd(adIRequest);
// Prepare an Interstitial Ad Listener
holder.interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
// Call displayInterstitial() function when the Ad loads
holder.displayInterstitial();
}
});
}
else if (
MediaIDHelper.isBrowseable(description.getMediaId())
&& (
MediaIDHelper.isEBook(description.getMediaId())) ||
MediaIDHelper.MEDIA_ID_BY_QUEUE.equals(description.getMediaId())
) {
convertView = LayoutInflater.
from(activity).
inflate(R.layout.fragment_ebook_item, parent, false);
}
else {
// Everything else
convertView = LayoutInflater.
from(activity).
inflate(R.layout.fragment_list_item, parent, false);
}
convertView.setTag(holder);
holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
if (holder.mTitleView != null) {
holder.mTitleView.setText(description.getTitle());
}
if (holder.mDescriptionView != null) {
holder.mDescriptionView.setText(description.getSubtitle());
}
if (holder.mImageView != null) {
int state = getMediaItemState(activity, item);
if (cachedState == null || cachedState != state) {
if (MediaIDHelper.isBrowseable(description.getMediaId())
|| MediaIDHelper.isEBookHeader(description.getMediaId()) ) {
Uri imageUri = item.getDescription().getIconUri();
GlideApp.
with(activity).
load(imageUri).
override(Target.SIZE_ORIGINAL).
fallback(R.drawable.default_book_cover).
error(R.drawable.default_book_cover).
/*listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
}).*/
into(holder.mImageView);
答案 0 :(得分:1)
您将广告放置在错误的位置, 将其放在一个片段中,否则“活动”将毫无问题地工作