开发者

how can i stop a function in a service?

I have a function::

public void doSleep() {
    handler.postDelayed(
        new Runnable() { 
      开发者_高级运维      public void run() { doCom(); } 
        }, 10000); 
}  

This is linked with doCom which starts this again. how can I finsh this at the end of the service?


you can also use

handler.removeCallbacks(Runnable r);


create a boolean flag in your class called sleep = true;

public void doSleep() {
    handler.postDelayed(
        new Runnable() { 
            public void run() { if(sleep) { doCom(); } } 
        }, 10000); 
}  

and set sleep = false; if you want to stop it.


use StopService() or StopSelf() methods where you want to stop

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜