title: Android Room database RxAndroid, Exception : java.lang.IllegalStateException: Cannot access database on the main thread since
body: <p>Currently, I am fetching data from Web API using RxAndroid and Retrofit, and want to store that Data in Room database but getting an exception</p>
  
  <p>As I search and found that, room database operations won't work on UI thread so I added <code>.subscribeOn(Schedulers.io())</code> in RXAndroid
  still it is throwing </p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Cannot access the database on the main thread since it may potentially lock the UI for a long period of time.</p>
  </blockquote>
  
  <pre><code>public void onClickLogin(View view) {
  
               io.reactivex.Observable
               .zip(getLogin(Constants.EMAILID, Constants.PASSWORD),
               getUserInfo(Constants.EMAILID, Constants.PASSWORD),
              getProductDetails(Constants.EMAILID, Constants.PASSWORD).subscribeOn(Schedulers.io()),
                                  .observeOn(AndroidSchedulers.mainThread())
                          new Function3&lt;List&lt;LoginModule&gt;,
                                  List&lt;UserInfoModule&gt;, ProductModule, AllZipData&gt;() {
                              @Override
                              public AllZipData apply(List&lt;LoginModule&gt; loginModuleList, List&lt;UserInfoModule&gt; useerInfoModules, ProductModule productModule) throws Exception {
  
                                  AllZipData allZipData = new AllZipData();
                                  allZipData.setLoginModuleList(loginModuleList);
                                  allZipData.setUserInfoModuleList(UserInfoModule);
                                  allZipData.setProductModule(productModule);
  
                                  return allZipData;
                              }
                          }).subscribe(new Observer&lt;AllZipData&gt;() {
              @Override
              public void onSubscribe(Disposable d) {
                  compositeDisposable.add(d);
              }
  
              @Override
              public void onNext(AllZipData allZipData) {
  
  
                  MyDatabase MyDatabase = MyDatabase.getInstance(context);
  
                  for (int i = 0; i &lt; allZipData.getUserInfoModuleList().size(); i++) {
  
                      UserInfoTable userInfoTable = new UserInfoTable();
                      userInfoTable.setValue1(allZipData.getUserInfoModuleList().get(i).getValue1());
                      userDatabase.userDao().insertUserInfo(userInfoTable);
                  }
  
              }
  
              @Override
              public void onError(Throwable e) {
                  Log.e(TAG, "onError: all zip data " + e.toString());
              }
  
              @Override
              public void onComplete() {
                  Log.e(TAG, "onComplete: all data zipped");
              }
          });
  }
  </code></pre>
  
  <p>how to solve this exception using RxAndroid.  </p>
  
  <p><strong>How to add retryWhen();?</strong></p>