尝试显示Google广告时发出警告

时间:2013-03-20 05:08:17

标签: android

我正在尝试展示我的Google广告,而我正在使用oncreate方法。

这就是我在做什么。

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cities);



        AdView adView = new AdView(this, AdSize.BANNER, "a150cb2e3184cd");
        LinearLayout addLay = (LinearLayout) findViewById(R.id.addlay);

        AdRequest adRequest = new AdRequest();
        // adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        addLay.addView(adView);
        adRequest.setTesting(true);
        adView.loadAd(adRequest);

但是当我运行我的应用程序时,我收到以下警告并且屏幕转换很慢。

这是警告

03-20 05:07:22.952: W/webview_proxy(8998): java.lang.Throwable: Warning: A WebView method was called on thread 'AsyncTask #4'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
03-20 05:07:22.952: W/webview_proxy(8998):  at android.webkit.WebView.checkThread(WebView.java:1876)
03-20 05:07:22.952: W/webview_proxy(8998):  at android.webkit.WebView.loadDataWithBaseURL(WebView.java:859)
03-20 05:07:22.952: W/webview_proxy(8998):  at c.a(Unknown Source)
03-20 05:07:22.952: W/webview_proxy(8998):  at c.doInBackground(Unknown Source)
03-20 05:07:22.952: W/webview_proxy(8998):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-20 05:07:22.952: W/webview_proxy(8998):  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-20 05:07:22.952: W/webview_proxy(8998):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-20 05:07:22.952: W/webview_proxy(8998):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-20 05:07:22.952: W/webview_proxy(8998):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-20 05:07:22.952: W/webview_proxy(8998):  at java.lang.Thread.run(Thread.java:856)

这是我的AsyncTask类

public class CityData extends AsyncTask<Integer, Void, String> {

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            try {
                if (!lstresponse.isEmpty()) {
                    lstresult.addAll(lstresponse);
                    lstcities.setAdapter(CustAdapter);
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        protected String doInBackground(Integer... params) {
            // TODO Auto-generated method stub

            SendRequesttoServer();
            return "1";
        }

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();

        }

    }

我在做什么错误?? ..

谢谢:)

1 个答案:

答案 0 :(得分:0)

由于AdView必须通过互联网进行通信,因此展示广告需要时间。

“阻止”或“滞后”可能是尝试向您展示广告的Ad SDK's主题。我真的不认为AdMob在尝试获取广告时会阻止UI主题,但是当您看到所有UI小部件项目(按钮,文本字段,图像)之间会有明显的延迟等等,在您的活动屏幕上以及广告出现时显示。

尝试在线程中加载广告,如下所示:

    public class MainActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          long now = System.currentTimeMillis();
      new Thread(new Runnable() {
      public void run() {
        new AdView(this, AdSize.BANNER, "MY_ID");               
      }
  }).start();
 }