Android 如何立即停止服务?

Android 如何立即停止服务?,android,service,Android,Service,在android开发中,我有一个由brodcastereceiver启动的服务,它正确地启动并完成了它的任务,但是当我试图使用stopself()从它的类中停止服务时;它直到执行了三次任务才停止,然后它的停止点是onStart服务和onDestroy()的代码;: 这是我从BrodCastereceiver启动服务时的代码: Intent intent =new Intent(context,RingService.class); context.startService(intent); 有

在android开发中,我有一个由brodcastereceiver启动的服务,它正确地启动并完成了它的任务,但是当我试图使用stopself()从它的类中停止服务时;它直到执行了三次任务才停止,然后它的停止点是onStart服务和onDestroy()的代码;:

这是我从BrodCastereceiver启动服务时的代码:

Intent intent =new Intent(context,RingService.class);
context.startService(intent);
有没有办法让我的服务在它自己完成任务后立即停止,或者我必须让BrodcastRecevicer停止它

我们将非常感谢您为解决此问题提供的任何帮助或重定向

关于

只需在onStart结束时调用stopSelf(),而不是onDestroy()调用,然后从onDestroy()中删除stopSelf()调用

Intent intent =new Intent(context,RingService.class);
context.startService(intent);