I'm trying to create an Observable that loads a file 10 times in a second and gives the result to Subscriber . However, Observable downloads the file once. Here is the code:
Observable.create((subscriber) -> { Log.i(TAG, "Загрузка начинается"); mDownloadHelper.downloadFile( mSharedPreferences.getString(DOC_URL_KEY, ""), Environment.DIRECTORY_DOWNLOADS, new DownloadHelper.DownloadListener() { @Override public void onDownloaded(Uri fileUri) { subscriber.onNext(fileUri); } @Override public void onFailed() { subscriber.onError(new Exception("Не выходит загрузить файл")); } }); Log.i(TAG, "Загрузка началась"); }) .repeat(10) .delay(1, TimeUnit.SECONDS) .observeOn(Schedulers.io()) .subscribeOn(Schedulers.io()) .subscribe(new Subscriber<Object>() { @Override public void onNext(Object o) { Log.i(TAG, "Загрузился!"); } @Override public void onError(Throwable e) { Log.i(TAG, "Ошибка!"); } @Override public void onCompleted() { Log.i(TAG, "Завершился"); //Не должно быть } }); As a result, the output log is:
10-23 15:04:24.744 24859-24886/com.dugin.rostislav.reminderofwork.doc_handling_service I/RLOG: Загрузка начинается 10-23 15:04:24.866 24859-24886/com.dugin.rostislav.reminderofwork.doc_handling_service I/RLOG: Загрузка началась 10-23 15:04:26.515 24859-24888/com.dugin.rostislav.reminderofwork.doc_handling_service I/RLOG: Загрузился! What is the problem and how to fix it?