我正在尝试展示我的谷歌广告,我正在使用 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();
}
}
我在做什么错???
谢谢:)