难道改造作出主线网络电话? [英] Does Retrofit make network calls on main thread?
本文介绍了难道改造作出主线网络电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想探讨的Android改造+ OkHttp。下面是一些code我在网上找到的:
I am trying to explore Retrofit+OkHttp on Android. Here's some code I found online :
RestAdapter restAdapter = new RestAdapter.Builder().setExecutors(executor, executor)
.setClient(new OkClient(okHttpClient))
.setServer("blah").toString())
.build();
如果我不使用执行人服务,将我的code是主线程上运行?我应该使Web请求,因此,一个新的线程?
If I don't use executor service, will my code be running on the main thread ? Should I make web requests in a new thread hence ?
推荐答案
这是返回一个值做它同步方式的方法。
The method that return a value does it Synchronously.
@GET("/user/{id}/asset")
Asset getUserAsset(@Path("id") int id);
要做到这一点异步所有你需要的是添加一个回调。
To do it Asynchronous all you need is to add a Callback.
@GET("/user/{id}/asset")
void getUserAsset(@Path("id") int id, Callback<Asset> cb);
希望这有助于。
Hope this Helps.
商祺!
这篇关于难道改造作出主线网络电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文