Good afternoon! I'm working with Executors, I have a button that when pressing it makes a toast every 5 seconds, my question is if there is a way to kill that process by pressing the button again.
I read that with future.cancel()
but I still can not implement it.
The following code is the one that shows the toast every 5 seconds
scheduleTaskExecutor = Executors.newScheduledThreadPool(0);
scheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MapActivity.this, "Mensaje cada 5 segundos", Toast.LENGTH_SHORT).show();
}
});
}
}, 0, 5, TimeUnit.SECONDS);
I hope you can help me. Thanks !!