你哪放线程中了? new Thread(new Runable(){ /*联网获取数据*/ }).start();
我new Runable(){}这个方法不是在线程中?
boolean android.view.View.postDelayed(Runnable action, long delayMillis) Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.Parameters: action The Runnable that will be executed. delayMillis The delay (in milliseconds) until the Runnable will be executed. Returns: true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped. See Also: post removeCallbacks
new Thread(new Runable(){
/*联网获取数据*/
}).start();
我new Runable(){}这个方法不是在线程中?
Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.Parameters:
action The Runnable that will be executed.
delayMillis The delay (in milliseconds) until the Runnable will be executed.
Returns:
true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting. Note that a result of true does not mean the Runnable will be processed -- if the looper is quit before the delivery time of the message occurs then the message will be dropped.
See Also:
post
removeCallbacks
我new Runable(){}这个方法不是在线程中?
runable是一个以过程方法函数,你使用Handle.postdelay;是指在一定时间之后去执行这个方法!thread才是线程! 你按照1楼的写法就可以了
1)网络代码不能在GUI主线程中执行。
2)楼主错误在于:XXX.postDelayed(new Runnable(){}),虽然new Runnable(){网络代码} ,但这不是一个线程,只是一个实现了Runnable接口的对象。然后:这个网络代码是通过postDelayed()方法还是提交给GUI主线程来做的。这就是错误的根源。