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
精彩评论