我想同时使用改造从服务器获得3个以上的响应。但只有2个请求将有响应。
我正在使用Retrofit和Rxjava。
我还使用.clone()方法重复请求。
点击(https://futurestud.io/tutorials/retrofit-2-reuse-and-analyze-requests-2)!
这是ResponseActivity:
location ~*.(apk)${
root /tmp/app;
add_header Content-Disposition attachment;
}
这是我的ViewModel
public class ResponseActivity extends AppCompatActivity {
private ResponseViewModel mViewModel;
private static final String TAG = "MainActivity";
private ProgressBar progressBar;
protected CompositeDisposable compositeDisposable = new CompositeDisposable();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.response_main);
mViewModel = new ResponseViewModel();
progressBar = findViewById(R.id.pb_response);
}
@Override
protected void onResume() {
super.onResume();
mViewModel.getText()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new MySingleObserver<Text>(compositeDisposable) {
@Override
public void onSuccess(Text value) {
Log.i(TAG, "onSuccess: " + value.getText());
}
});
mViewModel.getText()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new MySingleObserver<Text>(compositeDisposable) {
@Override
public void onSuccess(Text value) {
Log.i(TAG, "onSuccess: " + value.getText());
}
});
mViewModel.getText()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new MySingleObserver<Text>(compositeDisposable) {
@Override
public void onSuccess(Text value) {
Log.i(TAG, "onSuccess: " + value.getText());
}
});
}
@Override
protected void onPause() {
super.onPause();
compositeDisposable.clear();
}
}
我刚得到3分中的2分。有时我得到超过2。 我不知道为什么会这样。