问题描述
我有一个关于IntentService Android中的问题。我如下定义自己的服务:
I have a question about IntentService in Android. I define my own service as below:
公共类ABC扩展IntentService实现SensorEventListener {
public class ABC extends IntentService implements SensorEventListener {
@覆盖
保护无效onHandleIntent(意向意图){}
@Override protected void onHandleIntent(Intent intent) { }
@覆盖
公共无效onSensorChanged(SensorEvent事件){}
}
@Override public void onSensorChanged(SensorEvent event) { }}
现在,如果我开始从其他活动服务,onHandleIntent()被调用。文件说,它会启动一个工作线程来处理请求。然而,当onSensorChanged()方法被调用时,哪个线程将执行在onSensorChanged定义()方法code。这将是工作线程或主应用程序线程???
Now if i start the service from other activity, onHandleIntent() is invoked. Documentation says it launches a worker thread to process the request. However, when onSensorChanged() method is invoked, which thread will be executing the code defined in onSensorChanged() method. Will it be the worker thread or the main application thread???
推荐答案
按照 IntentService源$ C $ C ,IntentServices停止自己,当他们不再有任何消息(即 stopSelf
调用)。因此,如果你想有一个长期运行的服务
(我假设是适合你的 SensorEventListener
),那么你应该使用普通的服务
。
Per the IntentService source code, IntentServices stop themselves when they no longer have any messages (the stopSelf
call). Therefore if you want a long running Service
(which I assume would be appropriate for your SensorEventListener
), then you should use a regular Service
.
这篇关于Android的意图服务实施SensorEventListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!