我正在上传一个图像文件到安卓服务器上。我想知道上传completes.Is的时候有没有办法知道.如果android中有任何在上传完成时自动调用的状态。或者如何检查这种状态。
发布于 2011-04-20 00:59:47
如果您使用的是HttpClient.execute(),那么它就是一个同步方法--一旦上传完成,它就会返回。
编辑:据我所知,Android上没有异步HTTP客户端。对于非阻塞上传,使用HttpClient是一个工作线程,并使用Handler.post(Runnable)在主线程中处理完成。
EDIT2:异步HTTP如下所示:
final Handler Ha = new Handler(); //Used to post the results back to the main thread
new Thread(new Runnable(){
public void run()
{
HttpPost pr = new HttpPost(MyURL);
pr.setEntity(MyUploadData);
//More request setup...
HttpResponse Resp = new DefaultHttpClient().execute(pr);
//Process response here... detect errors, for one thing
Ha.post(new Runnable(){
public void run()
{
//This executes back in the main thread!
}
});
}
}).start();https://stackoverflow.com/questions/5719919
复制相似问题