Android Intent Service implementing SensorEventLis

2019-08-11 06:36发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-08-11 06:56

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.

查看更多
登录 后发表回答