My listener ChangeListener is triggered a second time in a second, and I need only the most recent of its operation from this heap (so as not to produce a lot of requests). If I wrote a JavaScript program, then I would process each trigger with the setTimeout function with 1 second interval, if this trigger should be followed by the next one, then I would cancel the first setTimeout and set a new one, as a result only a single trigger would be executed in a second. How do I implement this in Java?
Here is filtrRequestAdres(center); runs a bunch of times. How to implement onCameraChange filtering in it?
mMap.setOnCameraChangeListener(new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition pozCamera) { filtrRequestAdres(center); } }); public void filtrRequestAdres(LatLng center) { // if(...) { startIntentService(); } } How to postpone execution of a function in Java and how to cancel a deferred execution of a function? And so that the work of the delay program is not affected. :)
This is the thing that almost solves my question:
new android.os.Handler().postDelayed( new Runnable() { public void run() { Log.i("tag", "This'll run 300 milliseconds later"); } }, 300); It defers execution, but how to cancel this deferred execution?