title: Android RxFirebaseDatabase delaying subscription
body: <p>I use RxFirebaseDatabase by <a href="https://github.com/ezhome/Android-RxFirebase" rel="nofollow noreferrer">https://github.com/ezhome/Android-RxFirebase</a>.
  How do I delay subscription of observeValueEvent ? My code</p>
  
  <p>Fragment.java</p>
  
  <pre><code> Query fbQuery = firebaseRef.child("fireblog");
   RxFirebaseDatabase.getInstance()
            .observeValueEvent(fbQuery)
            .subscribe(getPostsSubscriber);
  </code></pre>
  
  <p>RxFirebaseDatabase.java method observeValueEvent</p>
  
  <pre><code>public Observable&lt;DataSnapshot&gt; observeValueEvent(final Query firebaseRef) {
      return Observable.create(new Observable.OnSubscribe&lt;DataSnapshot&gt;() {
          @Override
          public void call(final Subscriber&lt;? super DataSnapshot&gt; subscriber) {
              final ValueEventListener listener =
                      firebaseRef.addValueEventListener(new ValueEventListener() {
                          @Override
                          public void onDataChange(DataSnapshot dataSnapshot) {
                              subscriber.onNext(dataSnapshot);
                          }
  
                          @Override
                          public void onCancelled(DatabaseError error) {
                              FirebaseDatabaseErrorFactory.buildError(subscriber, error);
                          }
                      });
  
              // When the subscription is cancelled, remove the listener
              subscriber.add(Subscriptions.create(new Action0() {
                  @Override
                  public void call() {
                      firebaseRef.removeEventListener(listener);
                  }
              }));
          }
      })
              .delay(300, TimeUnit.MILLISECONDS)
              .compose(this.&lt;DataSnapshot&gt;applyScheduler());
  }
  </code></pre>
  
  <p>applyScheduler method</p>
  
  <pre><code>@SuppressWarnings("unchecked") private &lt;T&gt; Observable.Transformer&lt;T, T&gt; applyScheduler() {
  return new Observable.Transformer&lt;T, T&gt;() {
    @Override public Observable&lt;T&gt; call(Observable&lt;T&gt; observable) {
      if (observeOnScheduler != null) {
        return observable.observeOn(observeOnScheduler);
      }
      return observable;
    }
      };
    }
  </code></pre>
  
  <p>I get Fatal Exception thrown on <code>Scheduler.Worker</code> thread. Can you help me please ?</p>
  
  <p>logcat</p>
  
  <pre><code>   05-08 20:42:00.098 8366-8749/com.eusecom.attendance E/UncaughtException: java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
                                                                           at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:234)
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
                                                                           at java.lang.Thread.run(Thread.java:841)
                                                                        Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
                                                                           at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:187)
                                                                           at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
                                                                           at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:216)
                                                                           at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139)
                                                                           at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:87)
                                                                           at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189)
                                                                           at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                           at java.lang.Thread.run(Thread.java:841) 
                                                                        Caused by: rx.exceptions.CompositeException: 2 exceptions occurred. 
                                                                           at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:187) 
                                                                           at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) 
                                                                           at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:216) 
                                                                           at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139) 
                                                                           at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:87) 
                                                                           at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189) 
                                                                           at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                           at java.lang.Thread.run(Thread.java:841) 
                                                                        Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =&gt;
                                                                           at android.util.Log.getStackTraceString(Log.java:395)
                                                                           at android.util.Log.e(Log.java:315)
                                                                           at com.google.firebase.crash.internal.zzh.uncaughtException(Unknown Source)
                                                                           at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                                           at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
                                                                           at rx.internal.schedulers.ScheduledAction.signalError(ScheduledAction.java:68)
                                                                           at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                           at java.lang.Thread.run(Thread.java:841) 
                                                                        Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
                                                                           at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6809)
                                                                           at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1110)
                                                                           at android.view.ViewGroup.invalidateChild(ViewGroup.java:4484)
                                                                           at android.view.View.invalidate(View.java:11396)
                                                                           at android.view.View.invalidateParentIfNeeded(View.java:11482)
                                                                           at android.view.View.clearAnimation(View.java:17129)
                                                                           at com.eusecom.attendance.PostsFragment.showProgress(PostsFragment.java:220)
                                                                           at com.eusecom.attendance.PostsFragment.renderBlogPosts(PostsFragment.java:208)
                                                                           at com.eusecom.attendance.PostsFragment.access$600(PostsFragment.java:41)
                                                                           at com.eusecom.attendance.PostsFragment$GetPostsSubscriber.onNext(PostsFragment.java:258)
                                                                           at com.eusecom.attendance.PostsFragment$GetPostsSubscriber.onNext(PostsFragment.java:237)
                                                                           at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
                                                                           at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:87)
                                                                           at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189)
                                                                           at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                           at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                           at java.lang.Thread.run(Thread.java:841) 
                                                                        Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
                                                                           at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6809)
                                                                           at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1078)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                           at android.view.View.requestLayout(View.java:16775)
                                                                          at android.view.View.requestLayout(View.ja
   05-08 20:42:00.158 8366-8568/com.eusecom.attendance I/DynamiteModule: Considering local module com.google.android.gms.tagmanager:6 and remote module com.google.android.gms.tagmanager:9
   05-08 20:42:00.158 8366-8568/com.eusecom.attendance I/DynamiteModule: Selected remote version of com.google.android.gms.tagmanager, version &gt;= 9
   05-08 20:42:00.399 8366-8749/com.eusecom.attendance E/AndroidRuntime: FATAL EXCEPTION: RxComputationScheduler-1
                                                                    java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
                                                                        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
                                                                        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
                                                                        at java.lang.Thread.run(Thread.java:841)
                                                                     Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
                                                                        at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:187)
                                                                        at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
                                                                        at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:216)
                                                                        at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139)
                                                                        at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:87)
                                                                        at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189)
                                                                        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
                                                                        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                        at java.lang.Thread.run(Thread.java:841) 
                                                                     Caused by: rx.exceptions.CompositeException: 2 exceptions occurred. 
                                                                        at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:187) 
                                                                        at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115) 
                                                                        at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:216) 
                                                                        at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139) 
                                                                        at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:87) 
                                                                        at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189) 
                                                                        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55) 
                                                                        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                        at java.lang.Thread.run(Thread.java:841) 
                                                                     Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =&gt;
                                                                        at android.util.Log.getStackTraceString(Log.java:395)
                                                                        at android.util.Log.e(Log.java:315)
                                                                        at com.google.firebase.crash.internal.zzh.uncaughtException(Unknown Source)
                                                                        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                                        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
                                                                        at rx.internal.schedulers.ScheduledAction.signalError(ScheduledAction.java:68)
                                                                        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:59)
                                                                        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                        at java.lang.Thread.run(Thread.java:841) 
                                                                     Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
                                                                        at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6809)
                                                                        at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1110)
                                                                        at android.view.ViewGroup.invalidateChild(ViewGroup.java:4484)
                                                                        at android.view.View.invalidate(View.java:11396)
                                                                        at android.view.View.invalidateParentIfNeeded(View.java:11482)
                                                                        at android.view.View.clearAnimation(View.java:17129)
                                                                        at com.eusecom.attendance.PostsFragment.showProgress(PostsFragment.java:220)
                                                                        at com.eusecom.attendance.PostsFragment.renderBlogPosts(PostsFragment.java:208)
                                                                        at com.eusecom.attendance.PostsFragment.access$600(PostsFragment.java:41)
                                                                        at com.eusecom.attendance.PostsFragment$GetPostsSubscriber.onNext(PostsFragment.java:258)
                                                                        at com.eusecom.attendance.PostsFragment$GetPostsSubscriber.onNext(PostsFragment.java:237)
                                                                        at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
                                                                        at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:87)
                                                                        at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:189)
                                                                        at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
                                                                        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390) 
                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153) 
                                                                        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267) 
                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
                                                                        at java.lang.Thread.run(Thread.java:841) 
                                                                     Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
                                                                        at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6809)
                                                                        at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:1078)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                        at android.view.View.requestLayout(View.java:16775)
                                                                      at a
  </code></pre>