florent37 / RxGps

Finding current location cannot be easier on Android !
Apache License 2.0
300 stars 42 forks source link

How to stop get location #9

Open cahyofendhi opened 6 years ago

cahyofendhi commented 6 years ago

i have problem to stop get request location, after intent to another activity, request location still live, i have tried

disposable.dispose();

in destroy but not working, how to solve this

bluetoothfx commented 6 years ago

Same issue here. Followed like sample application. Also have tried compositeDisposable.dispose(); //may not needed compositeDisposable.clear();

onDestry() is calling fine on activity destroy. Problem is location sensor icon is not stopping showing.

Thanks, Any idea is welcome.

bluetoothfx commented 6 years ago

Followed the sample. Change the BaseActivity class like following. I have tested it. Please check and let me know if it works for you. Thanks.

package com.github.florent37.rxgps.sample;

import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity;

import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable;

public class BaseActivity extends AppCompatActivity {

private static CompositeDisposable compositeDisposable;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    compositeDisposable = new CompositeDisposable();
}

@Override
protected void onDestroy() {
    compositeDisposable.clear();
    super.onDestroy();
}

@Override
protected void onStop() {
    compositeDisposable.clear();
    super.onStop();
}

public void addDisposable(Disposable disposable){
    this.compositeDisposable.add(disposable);
}

}