|
44 | 44 | import io.reactivex.Single;
|
45 | 45 | import io.reactivex.SingleObserver;
|
46 | 46 | import io.reactivex.android.schedulers.AndroidSchedulers;
|
| 47 | +import io.reactivex.disposables.Disposable; |
47 | 48 | import io.reactivex.schedulers.Schedulers;
|
48 | 49 | import timber.log.Timber;
|
49 | 50 |
|
@@ -99,6 +100,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
|
99 | 100 | private boolean onOrientationChanged = false;
|
100 | 101 | private boolean populateForCurrentLocation = false;
|
101 | 102 | private boolean isNetworkErrorOccured = false;
|
| 103 | + private Disposable disposable; |
102 | 104 |
|
103 | 105 | @Override
|
104 | 106 | public void onCreate(@Nullable Bundle savedInstanceState) {
|
@@ -604,13 +606,13 @@ private void registerLocationUpdates() {
|
604 | 606 | */
|
605 | 607 | private void requestLocationPermissions() {
|
606 | 608 | if (!getActivity().isFinishing()) {
|
607 |
| - new Single<Object>(){ |
| 609 | + disposable = new Single<Object>() { |
608 | 610 | @Override
|
609 | 611 | protected void subscribeActual(SingleObserver<? super Object> observer) {
|
610 | 612 | locationManager.requestPermissions(getActivity());
|
611 | 613 | }
|
612 | 614 | }.subscribeOn(Schedulers.newThread())
|
613 |
| - .subscribe(); |
| 615 | + .subscribe(); |
614 | 616 | }
|
615 | 617 | }
|
616 | 618 |
|
@@ -803,6 +805,9 @@ public void onPause() {
|
803 | 805 | super.onPause();
|
804 | 806 | // this means that this activity will not be recreated now, user is leaving it
|
805 | 807 | // or the activity is otherwise finishing
|
| 808 | + if (disposable!=null) { |
| 809 | + disposable.dispose(); |
| 810 | + } |
806 | 811 | if(getActivity().isFinishing()) {
|
807 | 812 | // we will not need this fragment anymore, this may also be a good place to signal
|
808 | 813 | // to the retained fragment object to perform its own cleanup.
|
|
0 commit comments