2017-02-27 49 views
0

我已经在一个活动的不同时间启动了一些定时器。每个计时器都有自己的到期时间。但是我想停止所有在特定情况发生时在后台运行的定时器。停止在android中运行在后台的多个定时器

如何停止在Android的后台运行多个定时器?

+0

如何启动计时器?引用它们并调用https://developer.android.com/reference/java/util/Timer.html#cancel()? –

回答

0

您可以轻松取消定时器。 检查下面的代码。

private static Timer abc_Timer; 
abc_Timer=new Timer(); 
/*`your logic`*/ 
abc_Timer.cancel(); //cancel method will cancel your timer 
//After use of cancel method use 
abc_timer.purge(); //this method will remove all cancelled timer. 
相关问题