retrofit 使用详解
public class TestActivity extends RxBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_speed_test_new);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://www.speedtest.net/")
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
API api = retrofit.create(API.class);
disposables.add(api.config()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(responseBody -> {
Log.d(TAG, "result: " + responseBody.string());
((TextView) findViewById(R.id.tv_test)).setText("Hello, World!");
}));
}
interface API {
@GET("api/android/config.php")
Observable<ResponseBody> config();
}
}