Skip to content

Commit 4db28e8

Browse files
Fixes commons-app#2888: dispose of the single
1 parent fbafb86 commit 4db28e8

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import io.reactivex.Single;
4545
import io.reactivex.SingleObserver;
4646
import io.reactivex.android.schedulers.AndroidSchedulers;
47+
import io.reactivex.disposables.Disposable;
4748
import io.reactivex.schedulers.Schedulers;
4849
import timber.log.Timber;
4950

@@ -99,6 +100,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
99100
private boolean onOrientationChanged = false;
100101
private boolean populateForCurrentLocation = false;
101102
private boolean isNetworkErrorOccured = false;
103+
private Disposable disposable;
102104

103105
@Override
104106
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -604,13 +606,13 @@ private void registerLocationUpdates() {
604606
*/
605607
private void requestLocationPermissions() {
606608
if (!getActivity().isFinishing()) {
607-
new Single<Object>(){
609+
disposable = new Single<Object>() {
608610
@Override
609611
protected void subscribeActual(SingleObserver<? super Object> observer) {
610612
locationManager.requestPermissions(getActivity());
611613
}
612614
}.subscribeOn(Schedulers.newThread())
613-
.subscribe();
615+
.subscribe();
614616
}
615617
}
616618

@@ -803,6 +805,9 @@ public void onPause() {
803805
super.onPause();
804806
// this means that this activity will not be recreated now, user is leaving it
805807
// or the activity is otherwise finishing
808+
if (disposable!=null) {
809+
disposable.dispose();
810+
}
806811
if(getActivity().isFinishing()) {
807812
// we will not need this fragment anymore, this may also be a good place to signal
808813
// to the retained fragment object to perform its own cleanup.

0 commit comments

Comments
 (0)