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?

    1 answer 1

    Perhaps the replay will not be until the task is completed. Those. try to call after downloading the file

     subscriber.onCompleted(); 
    • It is not the answer to the question. To leave your comments or ask the author to clarify, leave a comment to the appropriate post. - From the queue of checks - Anton Shchyrov
    • Oh, Yuri! Do you still live here? :) - user189127
    • @AntonShchyrov, as practice has shown, this is quite an answer. It's just that he doesn't always have to be long and full of confidence in his accuracy) - Yuriy SPb
    • @ bukashka101, yes, yes ... That you have disappeared somewhere) - YuriiSPb
    • @Yuriy SPb, first went to read those. literature (read philosophy, Effective Java, Perfect code, etc.), and then went to write my project. - user189127