How to cancel all timers in Android application (started by new Timer()) if they exist now running in App? If needed, there is the Activity, that calls them. I have timer.cancel() on Activity destroy.
It's on that case that user will press Home button, then go to Apps, call App again and can launch this Activity with other parameter, so there may be 2 concurrent timers.
Something like "FOREACH TIMER IN TIMERS TIMER.CANCEL()"
1 Answer
You can do something like that:
List<Timer> timers = new ArrayList<Timer>(); //every time you starting new timer timers.add(new Timer()); //in onDestroy (or onPause, if you need) for (Timer timer : timers) { .... } super.onDestroy(); //super.onPause(); 1