如何立即停止服务? [英] How to stop service immediately?
问题描述
在Android开发,我有开始由Brodcastreceiver服务,并开始并适当做了它的任务,但是当我尝试使用stopself停止从其类服务();它并没有停止,直到完成其任务三次,然后在这里的站是code为在onStart服务的onDestroy();
In android development, I have service that started by Brodcastreceiver ,and it started and did its task properly , but when I try to stop the service from its class by using stopself(); it did not stop until performing its task three times and then its stop here is the code for the onStart service and onDestroy();:
@Override
public void onStart(Intent intent, int startid) {
player.start();
SystemClock.sleep(30000);
onDestroy();
}
@Override
public void onDestroy() {
player.stop();
this.stopSelf();}
和这里是code,当我开始从BrodcastReceiver服务:
and here is the code when I started the service from the BrodcastReceiver:
Intent intent =new Intent(context,RingService.class);
context.startService(intent);
有没有什么办法让我的服务立即停止一旦其自身完成了它的任务,或做我必须做BrodcastRecevicer阻止它?
Is there any way to make my service stop immediately once its finished its task by itself , or do I have to make the BrodcastRecevicer stop it?
任何帮助或重定向来解决这一问题将是completlly AP preciated
any help or redirection to solve this issue will be completlly appreciated
关于
推荐答案
就在调用onStart代替的onDestroy年底调用stopSelf()()调用,并从的onDestroy删除stopSelf()()调用。
Just call stopSelf() at the end of onStart instead of the onDestroy() call and remove the stopSelf() call from onDestroy().
这篇关于如何立即停止服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!