首页 文章

Android Intent Service实现SensorEventListener

提问于
浏览
1

我对Android中的IntentService有疑问 . 我定义自己的服务如下:

公共类ABC扩展IntentService实现SensorEventListener {

@Override protected void onHandleIntent(Intent intent){}

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

现在,如果我从其他活动启动服务,则调用onHandleIntent() . 文档说它启动了一个工作线程来处理请求 . 但是,当调用onSensorChanged()方法时,哪个线程将执行onSensorChanged()方法中定义的代码 . 它是工作线程还是主应用程序线程???

1 回答

  • 3

    根据IntentService source code,当IntentServices不再有任何消息( stopSelf 调用)时,它会自行停止 . 因此,如果你想要长时间运行 Service (我认为这适合你的 SensorEventListener ),那么你应该使用常规 Service .

相关问题