Skip to content

Commit

Permalink
removing reference to the view created by rx binding to avoid memory …
Browse files Browse the repository at this point in the history
…leak
  • Loading branch information
rijogeorge7 committed Jun 8, 2018
1 parent e4cae87 commit 6274b4f
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
import com.esoxjem.movieguide.details.MovieDetailsActivity;
import com.esoxjem.movieguide.details.MovieDetailsFragment;
import com.esoxjem.movieguide.Movie;
import com.esoxjem.movieguide.util.SoftKeyboardUtils;
import com.esoxjem.movieguide.util.RxUtils;
import com.esoxjem.movieguide.util.EspressoIdlingResource;
import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;

import java.util.concurrent.TimeUnit;
import io.reactivex.disposables.Disposable;


public class MoviesListingActivity extends AppCompatActivity implements MoviesListingFragment.Callback {
public static final String DETAILS_FRAGMENT = "DetailsFragment";
private boolean twoPaneMode;
private Disposable searchViewTextSubscription;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -77,7 +78,7 @@ public boolean onMenuItemActionCollapse(MenuItem item) {
}
});

RxSearchView.queryTextChanges(searchView)
searchViewTextSubscription = RxSearchView.queryTextChanges(searchView)
.debounce(500, TimeUnit.MILLISECONDS)
.subscribe(charSequence -> {
if (charSequence.length() > 0) {
Expand Down Expand Up @@ -126,4 +127,10 @@ private void loadMovieFragment(Movie movie) {
public IdlingResource getCountingIdlingResource() {
return EspressoIdlingResource.getIdlingResource();
}

@Override
protected void onDestroy() {
RxUtils.unsubscribe(searchViewTextSubscription);
super.onDestroy();
}
}

0 comments on commit 6274b4f

Please sign in to comment.