0

我正在尝试展示我的谷歌广告,我正在使用 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();

        }

    }

我在做什么错???

谢谢:)

4

1 回答 1

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();
 }
于 2013-03-20T06:18:40.410 回答