如何避免Admob的阻塞UI线程 [英] How to avoid Admob blocking the UI thread

查看:287
本文介绍了如何避免Admob的阻塞UI线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我的一些活动被阻止在发射升空。所以,我在一个新的项目写道:code:

I have detected some of my activities are blocked at the launch. So I wrote that code in a new project:

public class LayoutTestActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        long now = System.currentTimeMillis();

        new AdView(this, AdSize.BANNER, "MY_ID");

        Log.e("Admob Test","The UI was blocked "+(System.currentTimeMillis()-now)+"ms");
    }
}

和的结果是一个AD浏览对象块的第一建立为1至2秒UI线程

And the result is that the first creation of an AdView object blocks the UI thread for between 1 and 2 seconds.

有没有避免,有些方法是什么?

Is there some way of avoiding that?

感谢

推荐答案

您正在创建你的AD浏览报在UI线程这是被阻塞的原因。 虽然AD浏览报动初始化发生线程不会做别的。

You are creating your AdView in your UI thread which is the reason for getting blocked. While the AdView initilization takes place the thread wont do anything else.

您可以尝试加载你的AD浏览报在另一个线程或可以使用AsyncTask的加载它在UI安全的方式。

You can try loading your AdView in another thread or can use a AsyncTask to load it in a UI safe way.

选中此有关的AsyncTask和线程在Android的更多信息。

Check this for more info about AsyncTask and Threading in Android.

http://developer.android.com/reference/android/os/ AsyncTask.html

这篇关于如何避免Admob的阻塞UI线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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