我是否需要停止由 startWakefulService 启动的服务
Do I need to stop service started by startWakefulService
我的应用程序处理 GCM 广播并启动 IntentService 来处理它。该服务通过调用 startWakefulService 启动。在 onHandleIntent 结束时,调用 PushNotificationReceiver.completeWakefulIntent(intent)。
但是,我需要调用 stopService 或 stopSelf 来停止服务吗?如果我需要这样做,调用它的最佳位置是什么? GCM 示例似乎没有停止服务。它会自行停止吗?
不,您不必停止 IntentService。
IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.
我的应用程序处理 GCM 广播并启动 IntentService 来处理它。该服务通过调用 startWakefulService 启动。在 onHandleIntent 结束时,调用 PushNotificationReceiver.completeWakefulIntent(intent)。
但是,我需要调用 stopService 或 stopSelf 来停止服务吗?如果我需要这样做,调用它的最佳位置是什么? GCM 示例似乎没有停止服务。它会自行停止吗?
不,您不必停止 IntentService。
IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.