Android Intent Service implementing SensorEventListener

我的未来我决定 提交于 2020-01-05 10:16:13

问题


I have a question about IntentService in Android. I define my own service as below:

public class ABC extends IntentService implements SensorEventListener {

@Override protected void onHandleIntent(Intent intent) { }

@Override public void onSensorChanged(SensorEvent event) { } }

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???


回答1:


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.



来源:https://stackoverflow.com/questions/17480004/android-intent-service-implementing-sensoreventlistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!