what is the best way and bestpower-saving mode to get the following things in Android with LocationListener every 5 secounds:
I tried this (LocationListener):
@Override
public void onLocationChanged(Location location) {
// ...Code...
}
But this only update if Location changed but I need every 5 sec and only there. Maybe someone can show me an example.
Thanks for answers.
Use rxJava's method Observable.interval(5, TimeUnit.Seconds). ... and ubsubscribe from it when updates are no longer needed. In event handling (subscribe()) method poll location manually.
Subscription pollingConnection = Observable.interval(5, TimeUnit.SECONDS)
.observeOn(Schedulers.computation())
.map(t -> {
// get all your readings manually (it is executed in background because of
// .observeOn(Schedulers.computation())
return t;
})
.subscribe(t -> {
}, e -> {
});
// call pollingConnection.unsubscribe(); when update is no longer needed