服务是否自动停止本身onStartCommand()完成后? [英] Does Service stop itself automatically after onStartCommand() done?

查看:404
本文介绍了服务是否自动停止本身onStartCommand()完成后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我称之为 this.startService(新意图(这一点,Some_Service.class)); 结果
我知道,的onCreate()被称为其次为 onStartCommand()

When I call this.startService(new Intent(this, Some_Service.class));
I know that onCreate() is called and followed by onStartCommand().

柏迪什么,如果在 onStartCommand的code()完成情况?结果
是否服务自动调用的onDestroy()停止自己?结果
或者我必须调用 this.stopService(新意图(这一点,Some_Service.class)); 来实现这一目标。

Bur what happens if the code in onStartCommand() done?.
Does Service automatically call onDestroy() to stop itself?
Or do I must call this.stopService(new Intent(this, Some_Service.class)); to achieve that?

推荐答案

如果您通过调用启动服务 startService()然后你必须调用 stopService() stopSelf()停止服务。如果你想要做一些工作后停止服务,您可能需要使用 IntentService 代替。

If you start a service by calling startService() then you have to call stopService() or stopSelf() to stop the service. If you want to stop a service after doing some work, you might want to use IntentService instead.

这篇关于服务是否自动停止本身onStartCommand()完成后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆