难道改造作出主线网络电话?网络电话、主线

2023-09-13 00:27:52 作者:唐僧洗头爱飘柔

我想探讨的Andr​​oid改造+ 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.

商祺!