title: Using RxJava inside RecyclerView Adapter
body: <p>So a few weeks ago i asked this question: <a href="https://stackoverflow.com/questions/30402790/recyclerview-periodic-ui-child-updates/30403463#30403463">recyclerview periodic ui child updates</a>.</p>
  
  <p>And today i want to refactor that funcionality using Rxjava. It's actually pretty simple, i accomplish the following way:</p>
  
  <pre><code> @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
  
                  if (friend.getGameStatus().equals(GameStatus.INGAME)) {
                      holderOnline.startRepeatingTask();
                  } else {
                      holderOnline.stopRepeatingTask();
                  } 
      }
  
  
  class MyViewHolderOnline extends RecyclerView.ViewHolder {
  
      private Subscription subscribe;
  
          public MyViewHolderOnline(View itemView) {
              super(itemView);
              ButterKnife.bind(this, itemView);
  
          }
  
          public void startRepeatingTask() {
              subscribe = Observable.interval(updateInterval, TimeUnit.MILLISECONDS)
                      .map(aLong -&gt; current.getGameStatusToPrint())
                      .subscribeOn(Schedulers.io())
                      .observeOn(AndroidSchedulers.mainThread())
                      .subscribe(new Subscriber&lt;String&gt;() {
                          @Override public void onCompleted() { }
                          @Override public void onError(Throwable e) { }
  
                          @Override
                          public void onNext(String gameStatusToPrint) {
                              gameStatus.setText(gameStatusToPrint);
                          }
                      });
          }
  
          void stopRepeatingTask() {
              if(subscribe != null &amp;&amp; !subscribe.isUnsubscribed())
                  subscribe.unsubscribe();
          }
      }
  </code></pre>
  
  <p>The problem however is different. I have a navigationDrawer implemented with Activities that are Paused and not Destroyed when switched. So, after i switch to the activity that don't contains this adapter, the observable keeps on sending stuff because its a periodic interval Observable. So my question is, what should i do? I need to unsubscribe when the activity is paused, but i have no idea how since to, and also how to subscribe back. Any help or ideas? </p>