title: Paging library DataSource.Factory for multiple data sources android
body: <p>I have multiple data sources. But there is only one DataSourceFactory. So, all sources is sharing one factory. I need one DataSourceFactory per data source.</p>
  
  <p>In my app, I have multiple views with RecyclerViews and hence multiple custom data sources. So, do you end up creating multiple implementations of DataSource.Factory per data source or is there a more generic solution?</p>
  
  <p><strong>Edited</strong></p>
  
  <p>I found the solution in my case. In my previous version, I used only one Datasource Factory for all datasources. Now I create Datasource Factory Object whenever calling method from ViewModel like</p>
  
  <pre><code>private void initData(String id) {
      executor = Executors.newFixedThreadPool(5);
  
      factory = new EvaluationDataSourceFactory(compositeDisposable, api, id);
  
      networkState = Transformations.switchMap(factory.getDataSource(), source -&gt; {
                  Timber.d("network status get");
                  return source.getNetworkState();
              }
      );
  
      PagedList.Config pagedListConfig =
              (new PagedList.Config.Builder())
                      .setEnablePlaceholders(false)
                      .setInitialLoadSizeHint(5)
                      .setPrefetchDistance(5)
                      .setPageSize(5).build();
  
      error = Transformations.switchMap(factory.getDataSource(), source -&gt; {
          return source.getError();
      });
  
      assessments = (new LivePagedListBuilder(factory, pagedListConfig)).setFetchExecutor(executor).build();
  }
  
  public void getAssessments(String id) {
      initData(id);
  }
  </code></pre>
  
  <p>Then, you can call this method from your activity or fragment like</p>
  
  <pre><code>viewModel.getAssessments(id);
  </code></pre>
  
  <p>It worked for me.</p>