在后台线程上加载广告(adMob) [英] Loading Ad (adMob) on Background Thread

查看:92
本文介绍了在后台线程上加载广告(adMob)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在后台线程上加载我的add,因为它在打开和关闭时使SlidingMenu滞后.我应该使用Thread/Handler吗?还是AsyncTask?

I want to load my add on a background thread cause it makes the SlidingMenu laggy upon opening and closing. Should I use a Thread/Handler? Or AsyncTask?

String MY_AD_UNIT_ID = "----";
AdView adView = new AdView(getActivity(), AdSize.BANNER, MY_AD_UNIT_ID);
final LinearLayout adLayout = (LinearLayout) getActivity()
            .findViewById(R.id.adLayout);
adLayout.addView(adView);
adView.loadAd(new AdRequest());

推荐答案

我不认为可以这样做,因为所有与UI相关的工作都必须在主线程上完成.该API可能已经具有在网络上获取广告的线程.如果没有,如果在主线程上完成了任何与网络相关的工作,则android将抛出NetworkOnMainThreadException

I do not believe this can be done as all UI related stuff has to be done on the main thread. The API probably already has a thread to gets the ad on the network. If it didnt android would throw a NetworkOnMainThreadException if any network related stuff is done on the main thread

这篇关于在后台线程上加载广告(adMob)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆