How to avoid Admob blocking the UI thread

后端 未结 4 1577
忘了有多久
忘了有多久 2020-12-16 18:04

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 {

          


        
4条回答
  •  青春惊慌失措
    2020-12-16 18:43

    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.

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

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

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

提交回复
热议问题