OnCreate()
,因此运行良好public class MainActivity extends AppCompatActivity {
@Inject
Retrofit retrofit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((ThisForThatApplication)getApplication()).getNetComponent().inject(this);
}
Observable<CategoryHomeModel[]> categoriesObservable = retrofit.
.create(Restapi.class)
.getCategories1(new GetHeaders().prepareHeaders())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
}
答案 0 :(得分:0)
private Observable<CategoryHomeModel[]> getCategoriesObservable() {
Observable<CategoryHomeModel[]> categoriesObservable = retrofit
.create(Restapi.class)
.getCategories1(new GetHeaders().prepareHeaders())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
return categoriesObservable;
}
private Observable<WalletBalance> getWalletObservable() {
Observable<WalletBalance> walletObservable = retrofit
.create(Restapi.class)
.getWalletBalance1(new GetHeaders().prepareHeaders())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
return walletObservable;
}
private Observable<Settings> getSettingsObservable() {
Observable<Settings> settingsObservable = retrofit
.create(Restapi.class)
.getSettings1(new GetHeaders().prepareHeaders())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
return settingsObservable;
}
private Observable<SwapSettings> getRatingsObservble() {
Observable<SwapSettings> ratingsObservable = retrofit
.create(Restapi.class)
.rateMySwap1(new GetHeaders().prepareHeaders())
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
return ratingsObservable;
}
private void executeApis() {
List<Observable<?>> observables = Lists.newArrayList(getCategoriesObservable(),
getWalletObservable(), getSettingsObservable(), getRatingsObservble());
Observable.merge(observables).toList().subscribe(new Consumer<List<Object>>() {
@Override
public void accept(List<Object> objects) throws Exception {
Timber.d("");
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Timber.d("");
}
});
}