title: Rxjava Android saving to database after network call?
body: <p>I am learning rxjava on android and would like to accomplish the task of fetching data from the internet, showing to view and saving it to database. </p>
  
  <p>Once data is fetched from internet, I would like to in Parallel,</p>
  
  <ul>
  <li>Display fetched data to the View</li>
  <li>Save to Database (on computation thread)</li>
  </ul>
  
  <p>Also,</p>
  
  <ul>
  <li>If network fetch is success, then display to view + save to database (parallel)</li>
  <li>If network fetch is failure, the skip the whole process (onError())</li>
  <li>If saving to database fails, ignore and continue displaying to View.</li>
  </ul>
  
  <p>My problem is that if database part fails, nothing is displayed on the view.</p>
  
  <pre><code> @Override
    public Observable&lt;List&lt;NearByPlacesDetail&gt;&gt; getNearbyTouristSpotsList(String latlng) {
      Observable&lt;NearByPlacesMain&gt; nearByPlacesMainObservable = googleMapApi.getTouristAttractions(latlng);
  
  return nearByPlacesMainObservable
    .map(NearByPlacesMain::getResults)
    .onExceptionResumeNext(new Observable&lt;List&lt;NearByPlacesDetail&gt;&gt;() {
      @Override
      protected void subscribeActual(Observer&lt;? super List&lt;NearByPlacesDetail&gt;&gt; observer) {
        Throwable throwable = new Throwable("Network fetch error");
        Timber.e(throwable, "Error fetching data from internet.");
        observer.onError(throwable);
      }
    })
    .observeOn(Schedulers.computation())
    .doOnNext(nearByPlacesDetails -&gt; {
      databaseManager.getDatabase().delete(); // Force failure
      databaseManager.savePlacesList(nearByPlacesDetails);
    })
    .onExceptionResumeNext(new Observable&lt;List&lt;NearByPlacesDetail&gt;&gt;() {
      @Override
      protected void subscribeActual(Observer&lt;? super List&lt;NearByPlacesDetail&gt;&gt; observer) {
        Timber.e("Error saving to database.");
        observer.onComplete();
      }
    });
  </code></pre>
  
  <p>Presenter</p>
  
  <pre><code>getPlacesList.execute(new PlacesListObserver(), GetPlacesListUseCase.Params.forLocation(lat, lng));
  </code></pre>
  
  <p>Base UseCase (Domain Module)</p>
  
  <pre><code>  public void execute(DisposableObserver&lt;T&gt; observer, Params params) {
      Preconditions.checkNotNull(observer);
  
      final Observable&lt;T&gt; observable = this.buildUseCaseObservable(params)
        .subscribeOn(subscribeScheduler)
        .observeOn(observeScheduler);
  
      addDisposable(observable.subscribeWith(observer));
    }
  </code></pre>