title: How stop multiple retrofit calls when using it with Rx-Java used in search functionality for android?
body: <p>I have a search functionality in my Android app. The searchView has callback <code>onSearchTextChanged(String oldQuery, String newQuery)</code>. This callback function calls every time user enters any text to search field. I have a REST call in this callback which is triggering every time each word is being typed. Which leads to multiple calls for REST. I want to avoid that. I just want only one instance active at a time which is latest one and all other calls should be canceled instantly whenever the new letter is typed. Below are code details.</p>
  
  <pre><code> @Override
      public void onSearchTextChanged(String oldQuery, String newQuery) {
  
          floatingSearchView.showProgress();
          moviesAPI.searchQuery(newQuery)
                  .subscribeOn(Schedulers.newThread())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(new Subscriber&lt;Search&gt;() {
                                 @Override
                                 public void onCompleted() {
                                     Log.d(TAG, "onCompleted() called");
                                 }
  
                                 @Override
                                 public void onError(Throwable e) {
                                     Log.d(TAG, "onError() called with: e = [" + e + "]");
                                 }
  
                                 @Override
                                 public void onNext(Search search) {
                                     floatingSearchView.hideProgress();
                                     floatingSearchView.swapSuggestions(search.getSearchResults());
                                     Log.d(TAG, "onNext() called with: search = [" + search + "]");
                                 }
                             }
  
                  );
  
      }
  </code></pre>