title: Unsubscribe from Observable Rxjava
body: <p>I am quite new to Rx java observables so I am not sure when to unsubscribe. this is how my code implementation is </p>
  
  <pre><code>Observable&lt;String&gt; sampleObservable = Observable.just(accountNum);
          Subscription sampleSub = sampleObservable.subscribeOn(Schedulers.io()).subscribe(new Action1&lt;String&gt;() {
              @Override
              public void call(String accountNum) {
  
                  try {
                      //call backend api
                      AccountResponse response = getAccountDetails(accountNum);
                      logger.debug("Account response :" + response.toString());
  
                  } catch (Exception e) {
                      logger.error(e.getMessage());
  
                  }
  
              }
  
          });
  </code></pre>
  
  <p>Can I unsubscribe at the end "sampleSub.unsubscribe()".  The concern that I have here is if "getAccountDetails(accountNum)" call takes time to complete and the code unsubscribes then will it  cancel/affect the "getAccountDetails(accountNum)"  call? If yes, then is there a way to unsubscribe only when that call is over? </p>
  
  <pre><code>Observable&lt;String&gt; sampleObservable = Observable.just(accountNum);
      Subscription sampleSub = sampleObservable.subscribeOn(Schedulers.io()).subscribe(new Action1&lt;String&gt;() {
          @Override
          public void call(String accountNum) {
  
              try {
                  //call backend api
                  AccountResponse response = getAccountDetails(accountNum);
                  logger.debug("Account response :" + response.toString());
  
              } catch (Exception e) {
                  logger.error(e.getMessage());
  
              }
  
          }
  
      });
  
     //unsubscribing
      sampleSub.unsubscribe();
  </code></pre>